Skip to content

Commit dc66632

Browse files
guybedfordmarco-ippolito
authored andcommittedFeb 11, 2025
module: support 'module.exports' interop export in require(esm)
PR-URL: #54563 Backport-PR-URL: #56927 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> Refs: #52697
1 parent 1ac1dda commit dc66632

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
@@ -1382,10 +1382,13 @@ function loadESMFromCJS(mod, filename) {
13821382
// createRequiredModuleFacade() to `wrap` which is a ModuleWrap wrapping
13831383
// over the original module.
13841384

1385-
// We don't do this to modules that don't have default exports to avoid
1386-
// the unnecessary overhead. If __esModule is already defined, we will
1387-
// also skip the extension to allow users to override it.
1388-
if (!ObjectHasOwn(namespace, 'default') || ObjectHasOwn(namespace, '__esModule')) {
1385+
// We don't do this to modules that are marked as CJS ESM or that
1386+
// don't have default exports to avoid the unnecessary overhead.
1387+
// If __esModule is already defined, we will also skip the extension
1388+
// to allow users to override it.
1389+
if (ObjectHasOwn(namespace, 'module.exports')) {
1390+
mod.exports = namespace['module.exports'];
1391+
} else if (!ObjectHasOwn(namespace, 'default') || ObjectHasOwn(namespace, '__esModule')) {
13891392
mod.exports = namespace;
13901393
} else {
13911394
mod.exports = createRequiredModuleFacade(wrap);

0 commit comments

Comments
 (0)