diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 1fac67191b87df..45f685c71ad028 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -512,6 +512,7 @@ class ModuleLoader { * @returns {{ format: string, url: URL['href'] }} */ resolve(originalSpecifier, parentURL, importAttributes) { + originalSpecifier = `${originalSpecifier}`; if (this.#customizations) { return this.#customizations.resolve(originalSpecifier, parentURL, importAttributes); } @@ -530,6 +531,7 @@ class ModuleLoader { * `import.meta.resolve` which must happen synchronously. */ resolveSync(originalSpecifier, parentURL, importAttributes) { + originalSpecifier = `${originalSpecifier}`; if (this.#customizations) { return this.#customizations.resolveSync(originalSpecifier, parentURL, importAttributes); } diff --git a/test/es-module/test-esm-import-meta-resolve.mjs b/test/es-module/test-esm-import-meta-resolve.mjs index 4291f882753774..a9c26b7aecb926 100644 --- a/test/es-module/test-esm-import-meta-resolve.mjs +++ b/test/es-module/test-esm-import-meta-resolve.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-import-meta-resolve -import '../common/index.mjs'; +import { spawnPromisified } from '../common/index.mjs'; import assert from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -90,3 +90,20 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res cp.stdin.end('import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"'); assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/); } + +{ + const result = await spawnPromisified(execPath, [ + '--no-warnings', + '--input-type=module', + '--import', 'data:text/javascript,import{register}from"node:module";register("data:text/javascript,")', + '--eval', + 'console.log(import.meta.resolve(new URL("http://example.com")))', + ]); + + assert.deepStrictEqual(result, { + code: 0, + signal: null, + stderr: '', + stdout: 'http://example.com/\n', + }); +}