Repository navigation
[v20.6] CJS runs repeatedly when there are circular dependencies when loaded by ESM #49497
Description
Activity
- changed the title
[-][v20.6] CJS cycle dependency throwing error is loaded by ESM[/-][+][v20.6] CJS cycle dependencies throw an error when being loaded by ESM[/+]on Sep 5, 2023 - changed the title
[-][v20.6] CJS cycle dependencies throw an error when being loaded by ESM[/-][+][v20.6] CJS runs repeatedly when there are circular dependencies when loaded by ESM[/+]on Sep 5, 2023 - added a commit that references this issue
on Sep 5, 2023 - added a commit that references this issue
on Sep 5, 2023 Note that this is breaking
@babel/core, and thus all the frameworks/project that use it. It would be great to prioritize it 🙏Reacted by Kenichi Kamiya, Christopher Svanefalk, Filipoliko, Andras Serfozo, Eryk Baran, Evgeniy OZ, Matt, coderaiser, Luks17, yingziwu and 11 moreCan someone give a reproducible example? The code from https://github.com/liuxingbaoyu/node-v20.6-bug doesn't show the problem (it throws an error in
mod/index.js).Sorry, I forgot to push the second commit.
But the initial error is also different due to the regression.Please try again, thanks!
A minimal reproduction:
// index.mjs import "./dep.cjs";
// dep.cjs require("./dep.cjs"); console.log("RUNNING");
Running
node index.mjslogs twice but it should log once.Reacted by liuxingbaoyu and pvcresinI have a repro. Starting to bisect.
Reacted by Nicolò Ribaudo, liuxingbaoyu, Matthieu Riegler, Matthias Oßwald, Chemi Atlow, Christopher Svanefalk, Filipoliko, Konstantin Shutkin, Anderson Arboleya, Béré Cyriac and 2 more- added 2 commits that reference this issue
on Sep 5, 2023 @targos If it helps, it looks like the problem is that ESM's CJS loader doesn't set this
loaded = truebefore evaluating the CJS module.Here probably:
node/lib/internal/modules/esm/translators.js
Line 326 in 5b31ff1
cjsParseCache.set(module, { source, exportNames }); Bug is introduced by #47999
44 remaining items
- added 7 commits that reference this issue
on Sep 24, 2025 - added a commit that references this issue
on Jan 30, 2026 - added a commit that references this issue
on Feb 25, 2026 - added a commit that references this issue
on May 18, 2026 - added a commit that references this issue
on May 18, 2026 - added a commit that references this issue
on Jul 22, 2026
Version
v20.6.0
Platform
all
Subsystem
No response
What steps will reproduce the bug?
https://github.com/liuxingbaoyu/node-v20.6-bug
How often does it reproduce? Is there a required condition?
always
What is the expected behavior? Why is that the expected behavior?
What do you see instead?
Additional information
This should be the regression introduced by v20.6.