Skip to content

module: allow cycles in require() in the CJS handling in ESM loader - #58598

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
joyeecheung:fix-require-cycle
Jun 11, 2025
Merged

module: allow cycles in require() in the CJS handling in ESM loader#58598
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
joyeecheung:fix-require-cycle

Conversation

@joyeecheung

Copy link
Copy Markdown
Member

When --import is used, the ESM loader is used to handle even pure CJS entry points, and it can run into CJS module facades in the evaluating state when the parent CJS module is being evaluated. In this case it should be allowed, since the ESM <-> CJS cycles that are meant to be disallowed (for the time being) should already be detected before evaluation and wouldn't get here, and CJS <-> CJS cycles are fine.

Fixes: #58515

When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Jun 6, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecovBot commented Jun 6, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.14%. Comparing base (790acc8) to head (4d6f693).
Report is 63 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #58598 +/- ##
==========================================
- Coverage 90.22% 90.14% -0.09% 
==========================================
Files 635 636 +1 Lines 187492 187883 +391 Branches 36838 36890 +52 ==========================================
+ Hits 169169 169370 +201 - Misses 11097 11239 +142 - Partials 7226 7274 +48 
Files with missing linesCoverage Δ
lib/internal/modules/esm/module_job.js97.45% <100.00%> (+0.23%)⬆️
src/module_wrap.cc72.61% <ø> (+0.17%)⬆️

... and 66 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joyeecheung

Copy link
Copy Markdown
MemberAuthor

Fixed up the test which requires passing the URL into --import, not the path. Can you take a look again? @addaleax

@joyeecheungjoyeecheung added the review wanted PRs that need reviews. label Jun 9, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@joyeecheungjoyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed review wanted PRs that need reviews. labels Jun 11, 2025
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 11, 2025
@nodejs-github-bot
nodejs-github-bot merged commit 8c17ceb into nodejs:mainJun 11, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 8c17ceb

targos pushed a commit that referenced this pull request Jun 16, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
@joyeecheungjoyeecheung mentioned this pull request Jun 16, 2025
9 tasks
aduh95 pushed a commit that referenced this pull request Jul 21, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
aduh95 pushed a commit that referenced this pull request Jul 24, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
marco-ippolito pushed a commit to joyeecheung/node that referenced this pull request Aug 20, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: nodejs#58598Fixes: nodejs#58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
marco-ippolito pushed a commit that referenced this pull request Aug 20, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598
Backport-PR-URL: #59504Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 23, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598
Backport-PR-URL: #59504Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598
Backport-PR-URL: #59504Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598
Backport-PR-URL: #59504Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598
Backport-PR-URL: #59504Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 27, 2025
When --import is used, the ESM loader is used to handle even pure
CJS entry points, and it can run into CJS module facades in the
evaluating state when the parent CJS module is being evaluated.
In this case it should be allowed, since the ESM <-> CJS cycles
that are meant to be disallowed (for the time being) should
already be detected before evaluation and wouldn't get here,
and CJS <-> CJS cycles are fine.
PR-URL: #58598
Backport-PR-URL: #59504Fixes: #58515
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Refs: #52697
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.esmIssues and PRs related to the ECMAScript Modules implementation.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERR_INTERNAL_ASSERTION: Unexpected module status 3

5 participants

@joyeecheung@nodejs-github-bot@addaleax@Ethan-Arrowood@jsumners-nr