Repository navigation
Mocha ERR_REQUIRE_CYCLE_MODULE on latest CJS #57172
Description
Activity
It looks like there is an open PR in mocha for this mochajs/mocha#5294
I am not quite sure what that PR is doing, it would be more helpful if there is a minimal reproduction.
I'm not quite sure either, but following the discussion, it sounds like the issue is that these modules are supposed to be not found? mochajs/mocha#5290 (comment)
I could fix https://github.com/JoshuaKGoldberg/repros/tree/mocha-missing-module-cyclic with #57187 (fix is a funny word, as that graph is supposed to throw MODULE_NOT_FOUND and the fix is just to not shadow the linking error). I don't know if it fixes the regressions specifically reported here if that were tests that would've run fine, but it also includes handling for https://github.com/fisker/prettier-plugin-blade-311 which might have made evaluation that is supposed to proceed not proceed.
- addedmoduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.
on Feb 25, 2025 Thanks @joyeecheung for looking into this, I just built your fix here and can confirm your PR resolved this error handler ensuring that the not found error is correctly surfaced to users instead of the cycle error.
And to clarify - this only occurs when there is a failure due to a module not found, so on the error paths for tests. The bug thus being an error reporting bug only.
- added a commit that references this issue
on Mar 4, 2025 - added 2 commits that reference this issue
on Apr 2, 2025 4 remaining items
In what build this is fixed? I continue to experience that in 22.14.0
The fix was released in 22.15.0
- added 10 commits that reference this issue
on Aug 20, 2025
Version
22.4/23
Platform
Subsystem
modules
What steps will reproduce the bug?
See the upstream issue mochajs/mocha#5290.
With the backport to 22 this is affecting all my Mocha tests.
How often does it reproduce? Is there a required condition?
Unclear of the root cause currently.
What is the expected behavior? Why is that the expected behavior?
What do you see instead?
Additional information
No response