镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[v20.6] CJS runs repeatedly when there are circular dependencies when loaded by ESM #49497

Description

@liuxingbaoyu

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?

node .\main.js
run
success

What do you see instead?

node .\main.js
run
run
success

Additional information

This should be the regression introduced by v20.6.

Activity

  1. 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
  2. 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
  3. nicolo-ribaudo commented on Sep 5, 2023

    @nicolo-ribaudo
    Contributor

    Note that this is breaking@babel/core, and thus all the frameworks/project that use it. It would be great to prioritize it 🙏

  4. targos commented on Sep 5, 2023

    @targos
    Member

    Can 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).

  5. liuxingbaoyu commented on Sep 5, 2023

    @liuxingbaoyu
    ContributorAuthor

    Sorry, I forgot to push the second commit.
    But the initial error is also different due to the regression.

  6. liuxingbaoyu commented on Sep 5, 2023

    @liuxingbaoyu
    ContributorAuthor

    Please try again, thanks!

  7. nicolo-ribaudo commented on Sep 5, 2023

    @nicolo-ribaudo
  8. nicolo-ribaudo commented on Sep 5, 2023

    @nicolo-ribaudo
    Contributor

    A minimal reproduction:

    // index.mjs
    import "./dep.cjs";
    // dep.cjs
    require("./dep.cjs");
    console.log("RUNNING");

    Running node index.mjs logs twice but it should log once.

  9. targos commented on Sep 5, 2023

    @targos
    Member

    I have a repro. Starting to bisect.

  10. nicolo-ribaudo commented on Sep 5, 2023

    @nicolo-ribaudo
    Contributor

    @targos If it helps, it looks like the problem is that ESM's CJS loader doesn't set this loaded = true before evaluating the CJS module.

    Here probably:

    cjsParseCache.set(module, { source, exportNames });

  11. targos commented on Sep 5, 2023

    @targos
    Member

    Bug is introduced by #47999

  12. 44 remaining items

  13. added a commit that references this issue on Jul 22, 2026
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

    confirmed-bugIssues and PRs for confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.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