From ed3dfc5ee925c94dd832da3aa56479528ea4db3d 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. Refs: https://github.com/nodejs/node/pull/31906 --- 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