-
Notifications
You must be signed in to change notification settings - Fork 737
Runtime helper circular dependency when __exportAll is in entry chunk during code-splitting #8809
Description
Bug Description
When code-splitting, rolldown may place the runtime module (containing __exportAll, __commonJSMin, etc.) inside the entry chunk. If facade elimination later adds __exportAll dependency to a common chunk, that common chunk imports the helper from the entry chunk. When the entry chunk also imports from the common chunk (e.g., through static import chains), a circular dependency is created, causing the helper to be undefined at ESM evaluation time.
Reproduction
Project structure:
entry.js → gateway.js → daemon.js (barrel: export * from './impl.js')
↑
completion.js ──── dynamic import('./daemon.js')
Where entry.js also uses a CJS dependency (triggering __commonJSMin runtime helper, placing the runtime in the entry chunk).
Expected: __exportAll is imported from a standalone rolldown-runtime chunk or the chunk that defines it.
Actual: __exportAll is imported from index.js (entry chunk), creating a circular dependency:
daemon-cli-XXXX.js → import { __exportAll } from "./index.js"
index.js → import { ... } from "./daemon-cli-XXXX.js"
At runtime: TypeError: __exportAll is not a function
Root Cause
In chunk_optimizer.rs, optimize_facade_entry_chunks:
- The runtime module is assigned to the entry chunk during
split_chunks(because only the entry's CJS path references runtime helpers) - Facade elimination for dynamic entries adds
__exportAllto common chunks - The circular dependency check at line ~736 may be bypassed when
to_temp_idx()returnsNonefor newly created common chunks - The existing code at line ~1005 only handles the case where the runtime is NOT yet assigned (
module_to_chunk[runtime_module_idx].is_none()), missing the case where it's already in the entry chunk
Impact
- rc.3 → rc.10 fixed most instances (12 → 1 in our project), but edge cases remain
- The remaining case doesn't crash on startup but causes
undefinederrors when the affected dynamic import path is executed
Related Issues
- [Bug]: Circular deps caused by advancedChunks would throw error of referenced value is
undefined#3650 — Same class of bug (closed, but not fully fixed) - [Feat]: Inline
rolldown:runtimefor each chunk instead of share it #2654 — Proposes inlining runtime per-chunk as a more thorough solution
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority