Skip to content

Commit

Permalink
module: pass full URL to loader for top-level load
Browse files Browse the repository at this point in the history
PR-URL: #29736
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
guybedford authored and targos committed Oct 1, 2019
1 parent 69f2634 commit d1f4bef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ Module.runMain = function() {
// Load the main module--the command line argument.
if (experimentalModules) {
asyncESM.loaderPromise.then((loader) => {
return loader.import(pathToFileURL(process.argv[1]).pathname);
return loader.import(pathToFileURL(process.argv[1]).href);
})
.catch((e) => {
internalBinding('errors').triggerUncaughtException(
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/es-module-loaders/example-loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export function resolve(specifier, parentModuleURL = baseURL /*, defaultResolve
format: 'builtin'
};
}
if (/^\.{0,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
if (/^\.{1,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
// For node_modules support:
// return defaultResolve(specifier, parentModuleURL);
throw new Error(
`imports must begin with '/', './', or '../'; '${specifier}' does not`);
`imports must be URLs or begin with './', or '../'; '${specifier}' does not`);
}
const resolved = new url.URL(specifier, parentModuleURL);
const ext = path.extname(resolved.pathname);
Expand Down

0 comments on commit d1f4bef

Please sign in to comment.