Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 6e5232c

Browse files
guybedfordQard
authored andcommitted
module: fix hook module CJS dependency loading
It can be useful to load dependencies as part of the loader hook definition file. This fixes a bug where `import x from 'x'` would always return `x` as `undefined` if the import was made in a loader hooks definition module. A parallel change to the CJS loading injection process meant that the CJS module wasn't being injected into the correct loader instance, which is corrected here with a test. PR-URL: nodejs/node#16381 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 962431b commit 6e5232c

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

lib/module.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ Module._load = function(request, parent, isMain) {
431431
ESMLoader = new Loader();
432432
const userLoader = process.binding('config').userLoader;
433433
if (userLoader) {
434-
const hooks = await new Loader().import(userLoader);
434+
const hooks = await ESMLoader.import(userLoader);
435+
ESMLoader = new Loader();
435436
ESMLoader.hook(hooks);
436437
}
437438
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs
2+
/* eslint-disable required-modules */
3+
import './test-esm-ok.mjs';
4+
5+
// We just test that this module doesn't fail loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.format = 'esm';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import dep from './loader-dep.js';
2+
export function resolve (specifier, base, defaultResolve) {
3+
return {
4+
url: defaultResolve(specifier, base).url,
5+
format: dep.format
6+
};
7+
}

0 commit comments

Comments
 (0)