diff --git a/lib/module.js b/lib/module.js index d625bf96b932b5..2fba9d7bfac517 100644 --- a/lib/module.js +++ b/lib/module.js @@ -447,7 +447,8 @@ Module._load = function(request, parent, isMain) { ESMLoader = new Loader(); const userLoader = process.binding('config').userLoader; if (userLoader) { - const hooks = await new Loader().import(userLoader); + const hooks = await ESMLoader.import(userLoader); + ESMLoader = new Loader(); ESMLoader.hook(hooks); } } diff --git a/test/es-module/test-esm-loader-dependency.mjs b/test/es-module/test-esm-loader-dependency.mjs new file mode 100644 index 00000000000000..5d05118dbf2879 --- /dev/null +++ b/test/es-module/test-esm-loader-dependency.mjs @@ -0,0 +1,5 @@ +// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs +/* eslint-disable required-modules */ +import './test-esm-ok.mjs'; + +// We just test that this module doesn't fail loading diff --git a/test/fixtures/es-module-loaders/loader-dep.js b/test/fixtures/es-module-loaders/loader-dep.js new file mode 100644 index 00000000000000..cf821afec16e2c --- /dev/null +++ b/test/fixtures/es-module-loaders/loader-dep.js @@ -0,0 +1 @@ +exports.format = 'esm'; diff --git a/test/fixtures/es-module-loaders/loader-with-dep.mjs b/test/fixtures/es-module-loaders/loader-with-dep.mjs new file mode 100644 index 00000000000000..944e6e438c5cbd --- /dev/null +++ b/test/fixtures/es-module-loaders/loader-with-dep.mjs @@ -0,0 +1,7 @@ +import dep from './loader-dep.js'; +export function resolve (specifier, base, defaultResolve) { + return { + url: defaultResolve(specifier, base).url, + format: dep.format + }; +}