From 21c949d84f2e0ae28582a5e12a9afdc8aae562c2 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 20 Sep 2023 12:09:15 +0200 Subject: [PATCH] esm: fix return type of `import.meta.resolve` PR-URL: https://github.com/nodejs/node/pull/49698 Fixes: https://github.com/nodejs/node/issues/49695 Reviewed-By: Geoffrey Booth Reviewed-By: Guy Bedford --- lib/internal/errors.js | 2 +- test/es-module/test-esm-import-meta-resolve.mjs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index e84b9f6c851205..a8c2a9ea15db04 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1450,7 +1450,7 @@ E('ERR_MISSING_ARGS', E('ERR_MISSING_OPTION', '%s is required', TypeError); E('ERR_MODULE_NOT_FOUND', function(path, base, exactUrl) { if (exactUrl) { - lazyInternalUtil().setOwnProperty(this, 'url', exactUrl); + lazyInternalUtil().setOwnProperty(this, 'url', `${exactUrl}`); } return `Cannot find ${ exactUrl ? 'module' : 'package'} '${path}' imported from ${base}`; diff --git a/test/es-module/test-esm-import-meta-resolve.mjs b/test/es-module/test-esm-import-meta-resolve.mjs index 8495c161312822..a6435655750c88 100644 --- a/test/es-module/test-esm-import-meta-resolve.mjs +++ b/test/es-module/test-esm-import-meta-resolve.mjs @@ -9,10 +9,8 @@ const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) + assert.strictEqual(import.meta.resolve('./test-esm-import-meta.mjs'), dirname + 'test-esm-import-meta.mjs'); -const notFound = import.meta.resolve('./notfound.mjs'); -assert.strictEqual(new URL(notFound).href, new URL('./notfound.mjs', import.meta.url).href); -const noExtension = import.meta.resolve('./asset'); -assert.strictEqual(new URL(noExtension).href, new URL('./asset', import.meta.url).href); +assert.strictEqual(import.meta.resolve('./notfound.mjs'), new URL('./notfound.mjs', import.meta.url).href); +assert.strictEqual(import.meta.resolve('./asset'), new URL('./asset', import.meta.url).href); try { import.meta.resolve('does-not-exist'); assert.fail();