Skip to content

Mocha ERR_REQUIRE_CYCLE_MODULE on latest CJS #57172

Description

@guybedford

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

Activity

  1. joyeecheung commented on Feb 22, 2025

    @joyeecheung
    Member

    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.

  2. guybedford commented on Feb 22, 2025

    @guybedford
    ContributorAuthor

    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)

  3. joyeecheung commented on Feb 23, 2025

    @joyeecheung
    Member

    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.

  4. added
    moduleIssues and PRs related to the module subsystem.
    on Feb 25, 2025
  5. guybedford commented on Feb 25, 2025

    @guybedford
    ContributorAuthor

    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.

  6. 4 remaining items

  7. thesunlover commented on Jun 2, 2025

    @thesunlover

    In what build this is fixed? I continue to experience that in 22.14.0

  8. joyeecheung commented on Jun 2, 2025

    @joyeecheung
    Member

    The fix was released in 22.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions