Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: use correct URL for error decoration #37854

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 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 All @@ -120,7 +124,7 @@ class ModuleJob {
const importStatement = splitStack[1];
// TODO(@ctavan): The original error stack only provides the single
// line which causes the error. For multi-line import statements we
// cannot generate an equivalent object descructuring assignment by
// cannot generate an equivalent object destructuring assignment by
// just parsing the error stack.
const oneLineNamedImports = StringPrototypeMatch(importStatement, /{.*}/);
const destructuringAssignment = oneLineNamedImports &&
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');
}