From 43398d99bc7d4c5870266367b1891634f0ee5bb6 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Thu, 26 Sep 2019 23:20:09 -0400 Subject: [PATCH] module: pass full URL to loader for top-level load --- lib/internal/modules/cjs/loader.js | 2 +- test/fixtures/es-module-loaders/example-loader.mjs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 8ef01b4499a048..0ca88c3460414f 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -1002,7 +1002,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( diff --git a/test/fixtures/es-module-loaders/example-loader.mjs b/test/fixtures/es-module-loaders/example-loader.mjs index d8e0ddcba30699..ed5b0d9be5940d 100644 --- a/test/fixtures/es-module-loaders/example-loader.mjs +++ b/test/fixtures/es-module-loaders/example-loader.mjs @@ -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);