AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

TurbopackModuleFragments Split_module Index Mismatch Causes Panic On Empty Groups

split_module mixes group indices and compacted module positions; empty groups cause off-by-one leading to out-of-bounds panic in module_fragments/graph.rs:746.

highConfidence 95%Next.jsAffected V16.3.0Affected V16.3.4Affected V16.4.0-Canary.13

Origin Analysis

In split_module, the loop iterates over groups.graph_ix using group index ix, but when a chunk has empty body it is skipped with continue and not pushed to modules. Later, module_evaluation_ix and outputs entries are recorded using ix as u32 (group index) while other outputs use modules.len() (compacted module position). This index space mismatch causes modules[module_evaluation_ix] to access an out-of-bounds index when at least two empty groups occur.
1. Create a bare Next.js Pages Router app with no dependencies beyond next, react, react-dom. 2. Install next@16.3.4 react@19.2.8 react-dom@19.2.8. 3. Add next.config.js with `{ experimental: { turbopackModuleFragments: true } }`. 4. Create pages/index.js exporting a simple component. 5. Run `npx next build --turbopack`. 6. Observe panic: index out of bounds at turbopack/crates/turbopack-ecmascript/src/module_fragments/graph.rs:746.

Fixing Code Block

Edge Case Audit

Pushing empty chunks may slightly increase memory and processing overhead, and could theoretically affect tree shaking if downstream code assumes non-empty modules; however it is a minimal and safe change for the experimental flag. If unintended side effects occur, rollback this patch and implement an explicit group-to-module index mapping instead.

Ecosystem Topology