Skip to content

Commit d24c731

Browse files
committedOct 2, 2024·
module: support 'module.exports' interop export in require(esm)
PR-URL: #54563 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 2755551 commit d24c731

File tree

54 files changed

+308
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+308
-6
lines changed
 

Diff for: ‎doc/api/modules.md

+64-2

Diff for: ‎lib/internal/modules/cjs/loader.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1427,10 +1427,13 @@ function loadESMFromCJS(mod, filename) {
14271427
// createRequiredModuleFacade() to `wrap` which is a ModuleWrap wrapping
14281428
// over the original module.
14291429

1430-
// We don't do this to modules that don't have default exports to avoid
1431-
// the unnecessary overhead. If __esModule is already defined, we will
1432-
// also skip the extension to allow users to override it.
1433-
if (!ObjectHasOwn(namespace, 'default') || ObjectHasOwn(namespace, '__esModule')) {
1430+
// We don't do this to modules that are marked as CJS ESM or that
1431+
// don't have default exports to avoid the unnecessary overhead.
1432+
// If __esModule is already defined, we will also skip the extension
1433+
// to allow users to override it.
1434+
if (ObjectHasOwn(namespace, 'module.exports')) {
1435+
mod.exports = namespace['module.exports'];
1436+
} else if (!ObjectHasOwn(namespace, 'default') || ObjectHasOwn(namespace, '__esModule')) {
14341437
mod.exports = namespace;
14351438
} else {
14361439
mod.exports = createRequiredModuleFacade(wrap);

0 commit comments

Comments
 (0)
Please sign in to comment.