diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 37896f780f2..791bfd63baf 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -554,7 +554,7 @@ export class AssetGraphBuilder { this.options.projectRoot, loc?.filePath, ) ?? undefined, - language: assetNode.value.type, + language: incomingDep.value.sourceAssetType ?? undefined, codeHighlights: [ { start: loc.start, diff --git a/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json new file mode 100644 index 00000000000..9baad30d43d --- /dev/null +++ b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/package.json @@ -0,0 +1,3 @@ +{ + "source": "src/App.jsx" +} diff --git a/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx new file mode 100644 index 00000000000..95813b4cc76 --- /dev/null +++ b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/App.jsx @@ -0,0 +1,10 @@ +import React from "react"; +import { render } from "react-dom"; + +import * as styles from "./app.module.css" + +const App = function() { + return
+} + +render(, document.getElementById("app")) diff --git a/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/app.module.css b/packages/core/integration-tests/test/integration/no-export-error-with-correct-filetype/src/app.module.css new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/postcss.js b/packages/core/integration-tests/test/postcss.js index e4efd86bb28..07ebf71e3c4 100644 --- a/packages/core/integration-tests/test/postcss.js +++ b/packages/core/integration-tests/test/postcss.js @@ -623,4 +623,53 @@ describe('postcss', () => { await subscription.unsubscribe(); }); + + it('should throw an error when importing a missing class', async function () { + await assert.rejects( + () => + bundle( + path.join( + __dirname, + '/integration/no-export-error-with-correct-filetype/src/App.jsx', + ), + { + shouldDisableCache: true, + defaultTargetOptions: { + shouldScopeHoist: true, + }, + }, + ), + { + name: 'BuildError', + diagnostics: [ + { + codeFrames: [ + { + filePath: path.join( + __dirname, + '/integration/no-export-error-with-correct-filetype/src/App.jsx', + ), + language: 'js', + codeHighlights: [ + { + end: { + column: 45, + line: 7, + }, + start: { + column: 28, + line: 7, + }, + }, + ], + }, + ], + message: + "integration/no-export-error-with-correct-filetype/src/app.module.css does not export 'notExisting'", + origin: '@parcel/core', + }, + ], + }, + ); + }); });