module: fix extension lookups for top-level main

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 <myles.borins@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Guy Bedford 2017-10-26 21:52:00 +02:00 committed by Michaël Zasso
parent d853758a22
commit cadc47fe07
2 changed files with 8 additions and 1 deletions

View File

@ -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);

View File

@ -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']);