diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 3db047cd3274c4..8e6962e25645ea 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1228,7 +1228,9 @@ E('ERR_UNHANDLED_ERROR', E('ERR_UNKNOWN_BUILTIN_MODULE', 'No such built-in module: %s', Error); E('ERR_UNKNOWN_CREDENTIAL', '%s identifier does not exist: %s', Error); E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s', TypeError); -E('ERR_UNKNOWN_FILE_EXTENSION', 'Unknown file extension: %s', TypeError); +E('ERR_UNKNOWN_FILE_EXTENSION', + 'Unknown file extension "%s" for %s imported from %s', + TypeError); E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError); E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError); diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index c9ef3883c40412..d238930164dcf4 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -116,7 +116,10 @@ function resolve(specifier, parentURL) { 'ExperimentalWarning'); format = legacyExtensionFormatMap[ext]; } else { - throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url)); + throw new ERR_UNKNOWN_FILE_EXTENSION( + ext, + fileURLToPath(url), + fileURLToPath(parentURL)); } } return { url: `${url}`, format }; diff --git a/test/es-module/test-esm-invalid-extension.js b/test/es-module/test-esm-invalid-extension.js index cdf9476b29f864..87b0c6691d3445 100644 --- a/test/es-module/test-esm-invalid-extension.js +++ b/test/es-module/test-esm-invalid-extension.js @@ -6,8 +6,10 @@ const { spawnSync } = require('child_process'); const fixture = fixtures.path('/es-modules/import-invalid-ext.mjs'); const child = spawnSync(process.execPath, [fixture]); const errMsg = 'TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension'; +const importMsg = `imported from ${fixture}`; assert.strictEqual(child.status, 1); assert.strictEqual(child.signal, null); assert.strictEqual(child.stdout.toString().trim(), ''); assert(child.stderr.toString().includes(errMsg)); +assert(child.stderr.toString().includes(importMsg));