Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3902fa1

Browse files
guybedfordjoyeecheung
authored andcommittedFeb 5, 2025
module: support 'module.exports' interop export in require(esm)
PR-URL: nodejs#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 703803d commit 3902fa1

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
 

‎doc/api/modules.md

+64-2

‎lib/internal/modules/cjs/loader.js

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

1418-
// We don't do this to modules that don't have default exports to avoid
1419-
// the unnecessary overhead. If __esModule is already defined, we will
1420-
// also skip the extension to allow users to override it.
1421-
if (!ObjectHasOwn(namespace, 'default') || ObjectHasOwn(namespace, '__esModule')) {
1418+
// We don't do this to modules that are marked as CJS ESM or that
1419+
// don't have default exports to avoid the unnecessary overhead.
1420+
// If __esModule is already defined, we will also skip the extension
1421+
// to allow users to override it.
1422+
if (ObjectHasOwn(namespace, 'module.exports')) {
1423+
mod.exports = namespace['module.exports'];
1424+
} else if (!ObjectHasOwn(namespace, 'default') || ObjectHasOwn(namespace, '__esModule')) {
14221425
mod.exports = namespace;
14231426
} else {
14241427
mod.exports = createRequiredModuleFacade(wrap);

0 commit comments

Comments
 (0)
Please sign in to comment.