From a0effd38b40c0660c556222e70438f5e3ac040d9 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 26 Oct 2017 21:52:00 +0200 Subject: [PATCH] module: fix extension lookups for top-level main MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reason is that absolute URLs do not go through extension and index checks. By switching to an absolute path, the resolver still applies extensions properly to the top-level main. PR-URL: https://github.com/nodejs/node/pull/16526 Fixes: https://github.com/nodejs/node/issues/16476 Reviewed-By: Myles Borins Reviewed-By: Michaƫl Zasso Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum --- lib/module.js | 2 +- test/parallel/test-module-main-extension-lookup.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-module-main-extension-lookup.js diff --git a/lib/module.js b/lib/module.js index 2fba9d7bfac517..beeddc87941cb0 100644 --- a/lib/module.js +++ b/lib/module.js @@ -452,7 +452,7 @@ Module._load = function(request, parent, isMain) { ESMLoader.hook(hooks); } } - await ESMLoader.import(getURLFromFilePath(request).href); + await ESMLoader.import(getURLFromFilePath(request).pathname); })() .catch((e) => { console.error(e); diff --git a/test/parallel/test-module-main-extension-lookup.js b/test/parallel/test-module-main-extension-lookup.js new file mode 100644 index 00000000000000..0a8cc47c77b2ed --- /dev/null +++ b/test/parallel/test-module-main-extension-lookup.js @@ -0,0 +1,7 @@ +'use strict'; +require('../common'); +const { execFileSync } = require('child_process'); + +const node = process.argv[0]; + +execFileSync(node, ['--experimental-modules', 'test/es-module/test-esm-ok']);