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

‎lib/internal/modules/esm/module_job.js‎

Lines changed: 5 additions & 1 deletion
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
constsplitStack=StringPrototypeSplit(e.stack,'\n');
112-
constparentFileUrl=splitStack[0];
112+
constparentFileUrl=StringPrototypeReplace(
113+
splitStack[0],
114+
/:\d+$/,
115+
''
116+
);
113117
const{1: childSpecifier,2: name}=StringPrototypeMatch(
114118
e.message,
115119
/module'(.*)'doesnotprovideanexportnamed'(.+)'/);

‎test/fixtures/policy/bad-main.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import{doesNotExist}from'./dep.js';
Lines changed: 11 additions & 0 deletions
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+
}

‎test/parallel/test-policy-dependencies.js‎

Lines changed: 20 additions & 0 deletions
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+
constdepPolicy=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:Namedexport'doesNotExist'notfound\./,
110+
'Should give the real SyntaxError and position');
111+
}

0 commit comments

Comments
(0)