From 88d18026094916c5a2328449d4b7f90e966781f4 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 4c567ec2b9..921a57a814 100644 --- a/lib/module.js +++ b/lib/module.js @@ -436,7 +436,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 0000000000..0a8cc47c77 --- /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']);