From e53de96a8974099ca01b51870d44de2f2604ff1c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 15 May 2020 01:24:24 +0200 Subject: [PATCH] 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 --- lib/internal/modules/esm/resolve.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 8bff3fc9dfd251..cbcdb020ed7cd3 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