build: ERR_REQUIRE_CYCLE_MODULE when loading oxc-parser in StackBlitz / WebContainer
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #34551 @alan-agius4 による — マージ済み
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript, wasm
- 領域
- backend, build-system
調査の方向性
Start by reading the optionalDependencies in the @angular/build package manifest and compare them with the package's Oxc integration. Check how the proposed WASI binding dependency is resolved by oxc-parser in WebContainer. The issue is done when a clean install makes the binding available up front and Angular builds in WebContainer without the runtime download failure.
索引モデルが issue の本文から書いたものです。
説明
Command
build, serve
Is this a regression?
Yes, this behavior used to work in the previous version
Description
In StackBlitz (WebContainer), running an Angular application with @angular/build fails during ng serve / ng build with:
(node:12) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[oxc-parser] Downloading @oxc-parser/[email protected] on WebContainer...
Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /home/projects/stackblitz-starters-ki4mfjac/node_modules/oxc-parser/src-js/index.js in a cycle. (from /home/projects/stackblitz-starters-ki4mfjac/node_modules/@angular/build/src/tools/oxc/oxc-transform.js) A cycle involving require(esm) is not allowed to maintain invariants mandated by the ECMAScript specification. Try making at least part of the dependency in the graph lazily loaded.
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:169:3960)
at loadESMFromCJS (node:internal/modules/cjs/loader:160:19002)
at Module._compile (node:internal/modules/cjs/loader:160:19068)
at Module._extensions..js (node:internal/modules/cjs/loader:160:20043)
at Module.load (node:internal/modules/cjs/loader:160:17661)
at Module._load (node:internal/modules/cjs/loader:160:15179)
at wrapModuleLoad (node:internal/modules/cjs/loader:160:4199)
at Module.require (node:internal/modules/cjs/loader:160:17842)
at require2 (node:internal/modules/helpers:177:3126) {
code: 'ERR_REQUIRE_CYCLE_MODULE'
}
Parent issue: https://github.com/stackblitz/starters/issues/136
Analysis & Root Cause
-
No actual cyclic dependency in the code:
The module graph (oxc-transform.ts->oxc-parser,oxc-transform.ts->traversal.ts->oxc-parser) is an acyclic DAG.
TheERR_REQUIRE_CYCLE_MODULEerror is a known misleading error in Node.js's synchronousrequire(esm)loader (Node.js issues #55516 and #57172). When an ES module throws an error during synchronousrequire(esm)evaluation, Node's loader frequently shadows the real underlying exception and reports that the module was required in a cycle. -
WebContainer Fallback Failure:
- StackBlitz WebContainer cannot run native
.nodeaddons. oxc-parser'soptionalDependenciesonly list platform-specific native addons (@oxc-parser/binding-linux-x64-gnu, etc.) and do not list@oxc-parser/binding-wasm32-wasi. Consequently, package managers running in WebContainer never install the WASI binding.- At runtime,
oxc-parser/src-js/bindings.jsdetects WebContainer and falls back towebcontainer-fallback.cjs, which attempts to runchildProcess.execFileSync("pnpm", ["i", "@oxc-parser/binding-wasm32-wasi@..."], { cwd: "/tmp/..." }). - Running this synchronous subprocess from a worker thread inside WebContainer fails (or fails to initialize the multi-threaded WASI runtime), causing the synchronous
require(esm)evaluation ofoxc-parserto fail and surface asERR_REQUIRE_CYCLE_MODULE.
- StackBlitz WebContainer cannot run native
Proposed Solution (Option 4A: Add @oxc-parser/binding-wasm32-wasi to @angular/build optionalDependencies)
In oxc-parser/src-js/bindings.js, before falling back to webcontainer-fallback.cjs, it checks:
__napiWasiResolveCandidate('@oxc-parser/binding-wasm32-wasi', true, undefined)
If @oxc-parser/binding-wasm32-wasi is already present in node_modules, oxc-parser directly loads it and bypasses webcontainer-fallback.cjs and the dynamic pnpm i in /tmp entirely.
A viable solution (Option 4A) is to declare @oxc-parser/binding-wasm32-wasi in @angular/build's optionalDependencies (similar to how lmdb is declared).
This ensures that package managers install the WASI binding up-front alongside @angular/build, preventing the runtime dynamic installation and the resulting failure in WebContainer.
Minimal Reproduction
- Open https://stackblitz.com/edit/stackblitz-starters-ki4mfjac?file=package.json (or update any StackBlitz Angular starter to Angular CLI v22.2+).
- Run
npm install && npm start(orng serve). - Notice the build fails with
ERR_REQUIRE_CYCLE_MODULE: Cannot require() ES Module .../oxc-parser/src-js/index.js in a cycle.
Exception or Error
(node:12) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[oxc-parser] Downloading @oxc-parser/[email protected] on WebContainer...
Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /home/projects/stackblitz-starters-ki4mfjac/node_modules/oxc-parser/src-js/index.js in a cycle. (from /home/projects/stackblitz-starters-ki4mfjac/node_modules/@angular/build/src/tools/oxc/oxc-transform.js) A cycle involving require(esm) is not allowed to maintain invariants mandated by the ECMAScript specification. Try making at least part of the dependency in the graph lazily loaded.
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:169:3960)
at loadESMFromCJS (node:internal/modules/cjs/loader:160:19002)
at Module._compile (node:internal/modules/cjs/loader:160:19068)
at Module._extensions..js (node:internal/modules/cjs/loader:160:20043)
at Module.load (node:internal/modules/cjs/loader:160:17661)
at Module._load (node:internal/modules/cjs/loader:160:15179)
at wrapModuleLoad (node:internal/modules/cjs/loader:160:4199)
at Module.require (node:internal/modules/cjs/loader:160:17842)
at require2 (node:internal/modules/helpers:177:3126) {
code: 'ERR_REQUIRE_CYCLE_MODULE'
}
Node.js v22.22.3
Your Environment
Angular CLI: 22.2.3
Node: 22.22.3 (WebContainer)
OS: linux x64 (WebContainer)
Anything else relevant?
Parent issue: https://github.com/stackblitz/starters/issues/136
- 主要言語
- TypeScript
- スター
- 27k
- フォーク
- 11.8k
- 平均マージ
- 1日 5時間
- マージ済み PR(30日)
- 280
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
angular/angular-cli のほかの issue
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンarea: @angular/build gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
angular/angular-cli#33955 ·
メンテナーはふだん 1 日以内に返信
-
Allow tests to pass without any test files (e.g. via Vitest `passWithNoTests`)再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンarea: @angular/cli gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
angular/angular-cli#33055 · コメント 1 件 · リアクション 3 件 ·
メンテナーはふだん 1 日以内に返信
-
@angular/build: source-map comment scanner corrupts valid JS containing a regex literal対応中かも @alan-agius4 が 1 日前に担当しました。 オープンarea: @angular/build
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
angular/angular-cli#34590 ·
メンテナーはふだん 1 日以内に返信
-
Debug ID changes the bytes of an optimized chunk but not its file name, so cached files fail the SRI check対応中かも @alan-agius4 が 1 日前に担当しました。 オープンarea: @angular/build
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
angular/angular-cli#34574 · リアクション 4 件 ·
メンテナーはふだん 1 日以内に返信
-
Angular SSR prerender params allow build-time SSRF, credential leaks, and open redirects対応中かも @SkyZeroZx が 2 日前に担当しました。 オープンarea: @angular/ssr
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
angular/angular-cli#34569 ·
メンテナーはふだん 1 日以内に返信
angular/angular-cli の issue をすべて見る
似ている issue
-
bug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
hemi-earn
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
vetro-protocol/vetro-monorepo#1043 ·
メンテナーはふだん 1 日以内に返信
-
stage 2: bare names resolve against PATH differently from the shell (empty and relative entries)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
STRML/omp-classifier#206 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
atlassian-labs/mermaid-diagrams-viewer#188 ·
メンテナーはふだん 1 日以内に返信
-
dashboard enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Olanetsoft/agent-lookout#225 ·
メンテナーはふだん 1 日以内に返信