Skip to content

Commit 83ba688

Browse files
marco-ippolitoaduh95
authored andcommitted
esm: fix import.meta.resolve crash
PR-URL: #55777 Fixes: #55518 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 9aeb671 commit 83ba688

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/node_modules.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ void BindingData::GetPackageScopeConfig(
412412
}
413413

414414
auto file_url = url::FileURLToPath(realm->env(), *package_json_url);
415-
CHECK(file_url);
415+
if (!file_url) {
416+
url::ThrowInvalidURL(realm->env(), resolved.ToStringView(), std::nullopt);
417+
return;
418+
}
416419
error_context.specifier = resolved.ToString();
417420
auto package_json = GetPackageJSON(realm, *file_url, &error_context);
418421
if (package_json != nullptr) {

test/es-module/test-esm-import-meta-resolve.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,15 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res
106106
stdout: 'http://example.com/\n',
107107
});
108108
}
109+
110+
{
111+
const result = await spawnPromisified(execPath, [
112+
'--no-warnings',
113+
'--experimental-import-meta-resolve',
114+
'--eval',
115+
'import.meta.resolve("foo", "http://example.com/bar.js")',
116+
]);
117+
assert.match(result.stderr, /ERR_INVALID_URL/);
118+
assert.strictEqual(result.stdout, '');
119+
assert.strictEqual(result.code, 1);
120+
}

0 commit comments

Comments
 (0)