Skip to content

Commit

Permalink
Improve constant module bundling error message (#9803)
Browse files Browse the repository at this point in the history
* Improve constant module bundling error message

* Avoid work when not throwing error
  • Loading branch information
marcins authored Jun 18, 2024
1 parent 2ce4efe commit 53161b4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/packagers/js/src/ScopeHoistingPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@parcel/utils';
import SourceMap from '@parcel/source-map';
import nullthrows from 'nullthrows';
import invariant from 'assert';
import invariant, {AssertionError} from 'assert';
import ThrowableDiagnostic, {
convertSourceLocationToHighlight,
} from '@parcel/diagnostic';
Expand Down Expand Up @@ -922,10 +922,17 @@ ${code}

isWrapped(resolved: Asset, parentAsset: Asset): boolean {
if (resolved.meta.isConstantModule) {
invariant(
this.bundle.hasAsset(resolved),
'Constant module not found in bundle',
);
if (!this.bundle.hasAsset(resolved)) {
throw new AssertionError({
message: `Constant module ${path.relative(
this.options.projectRoot,
resolved.filePath,
)} referenced from ${path.relative(
this.options.projectRoot,
parentAsset.filePath,
)} not found in bundle ${this.bundle.name}`,
});
}
return false;
}
return (
Expand Down

0 comments on commit 53161b4

Please sign in to comment.