Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2020-05-15 02:24:24 +0300
committerGuy Bedford <guybedford@gmail.com>2020-05-16 05:09:01 +0300
commit1cb80d1e0590eeb3daf495bddfcf5237a99aa9b7 (patch)
treeeeeca6040b58838119a7ba3101eb49db91f14bf4
parent985e9c5fe535e31fb26665dce7c0659b4ae61d21 (diff)
esm: improve commonjs hint on module not found
Adds hint when module specifier is a file URL. PR-URL: https://github.com/nodejs/node/pull/33220 Fixes: https://github.com/nodejs/node/issues/33219 Reviewed-By: Guy Bedford <guybedford@gmail.com>
-rw-r--r--lib/internal/modules/esm/resolve.js3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
index 8bff3fc9dfd..cbcdb020ed7 100644
--- a/lib/internal/modules/esm/resolve.js
+++ b/lib/internal/modules/esm/resolve.js
@@ -758,6 +758,9 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) {
// resolved CommonJS module
if (error.code === 'ERR_MODULE_NOT_FOUND' ||
error.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
+ if (StringPrototypeStartsWith(specifier, 'file://')) {
+ specifier = fileURLToPath(specifier);
+ }
const found = resolveAsCommonJS(specifier, parentURL);
if (found) {
// Modify the stack and message string to include the hint