Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e683077

Browse filesBrowse files
guybedfordgibfahn
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: #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 b1e2a38 commit e683077
Copy full SHA for e683077

File tree

Expand file treeCollapse file tree

4 files changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎lib/module.js‎

Copy file name to clipboardExpand all lines: lib/module.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ Module._load = function(request, parent, isMain) {
447447
ESMLoader = new Loader();
448448
const userLoader = process.binding('config').userLoader;
449449
if (userLoader) {
450-
const hooks = await new Loader().import(userLoader);
450+
const hooks = await ESMLoader.import(userLoader);
451+
ESMLoader = new Loader();
451452
ESMLoader.hook(hooks);
452453
}
453454
}
Collapse file
+5Lines changed: 5 additions & 0 deletions
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
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.format = 'esm';
Collapse file
+7Lines changed: 7 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.