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 authored and targos committed Sep 4, 2021
1 parent 37b4708 commit d42bbe4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/internal/modules/esm/module_job.js
Expand Up @@ -133,9 +133,14 @@ class ModuleJob {
StringPrototypeIncludes(e.message,
' does not provide an export named')) {
const splitStack = StringPrototypeSplit(e.stack, '\n');
const parentFileUrl = splitStack[0];
const [, childSpecifier, name] = StringPrototypeMatch(e.message,
/module '(.*)' does not provide an export named '(.+)'/);
const parentFileUrl = StringPrototypeReplace(
splitStack[0],
/:\d+$/,
''
);
const { 1: childSpecifier, 2: name } = StringPrototypeMatch(
e.message,
/module '(.*)' does not provide an export named '(.+)'/);
const childFileURL =
await this.loader.resolve(childSpecifier, parentFileUrl);
const format = await this.loader.getFormat(childFileURL);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/policy/bad-main.mjs
@@ -0,0 +1 @@
import {doesNotExist} from './dep.js';
@@ -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
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 d42bbe4

Please sign in to comment.