Skip to content

Commit

Permalink
esm: use correct URL for error decoration
Browse files Browse the repository at this point in the history
PR-URL: #37854
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
  • Loading branch information
bmeck committed Apr 12, 2021
1 parent c8bbd83 commit 8dd0685
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ class ModuleJob {
if (StringPrototypeIncludes(e.message,
' does not provide an export named')) {
const splitStack = StringPrototypeSplit(e.stack, '\n');
const parentFileUrl = splitStack[0];
const parentFileUrl = StringPrototypeReplace(
splitStack[0],
/:\d+$/,
''
);
const { 1: childSpecifier, 2: name } = StringPrototypeMatch(
e.message,
/module '(.*)' does not provide an export named '(.+)'/);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/policy/bad-main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import {doesNotExist} from './dep.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"resources": {
"../bad-main.mjs": {
"integrity": true,
"dependencies": true
},
"../dep.js": {
"integrity": true
}
}
}
20 changes: 20 additions & 0 deletions test/parallel/test-policy-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,23 @@ const dep = fixtures.path('policy', 'parent.js');
);
assert.strictEqual(status, 1);
}
{
// Regression test for https://github.com/nodejs/node/issues/37812
const depPolicy = fixtures.path(
'policy',
'dependencies',
'dependencies-missing-export-policy.json');
const { status, stderr } = spawnSync(
process.execPath,
[
'--experimental-policy',
depPolicy,
fixtures.path('policy', 'bad-main.mjs'),
]
);
assert.strictEqual(status, 1);
assert.match(
`${stderr}`,
/SyntaxError: Named export 'doesNotExist' not found\./,
'Should give the real SyntaxError and position');
}

0 comments on commit 8dd0685

Please sign in to comment.