Skip to content

Commit 8dd0685

Browse files
committed
esm: use correct URL for error decoration
PR-URL: #37854 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]>
1 parent c8bbd83 commit 8dd0685

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Diff for: lib/internal/modules/esm/module_job.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ class ModuleJob {
109109
if (StringPrototypeIncludes(e.message,
110110
' does not provide an export named')) {
111111
const splitStack = StringPrototypeSplit(e.stack, '\n');
112-
const parentFileUrl = splitStack[0];
112+
const parentFileUrl = StringPrototypeReplace(
113+
splitStack[0],
114+
/:\d+$/,
115+
''
116+
);
113117
const { 1: childSpecifier, 2: name } = StringPrototypeMatch(
114118
e.message,
115119
/module '(.*)' does not provide an export named '(.+)'/);

Diff for: test/fixtures/policy/bad-main.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import {doesNotExist} from './dep.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"resources": {
3+
"../bad-main.mjs": {
4+
"integrity": true,
5+
"dependencies": true
6+
},
7+
"../dep.js": {
8+
"integrity": true
9+
}
10+
}
11+
}

Diff for: test/parallel/test-policy-dependencies.js

+20
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,23 @@ const dep = fixtures.path('policy', 'parent.js');
8989
);
9090
assert.strictEqual(status, 1);
9191
}
92+
{
93+
// Regression test for https://github.com/nodejs/node/issues/37812
94+
const depPolicy = fixtures.path(
95+
'policy',
96+
'dependencies',
97+
'dependencies-missing-export-policy.json');
98+
const { status, stderr } = spawnSync(
99+
process.execPath,
100+
[
101+
'--experimental-policy',
102+
depPolicy,
103+
fixtures.path('policy', 'bad-main.mjs'),
104+
]
105+
);
106+
assert.strictEqual(status, 1);
107+
assert.match(
108+
`${stderr}`,
109+
/SyntaxError: Named export 'doesNotExist' not found\./,
110+
'Should give the real SyntaxError and position');
111+
}

0 commit comments

Comments
 (0)