Skip to content

Turbopack panics in ModuleGraphImportTracer: 'entered unreachable code: there must be a path to a root' (module_graph/mod.rs:750) #98205

Description

@agentHits

Link to the code that reproduces this issue

https://github.com/agentHits/next-prerender-workstore-reproduction

To Reproduce

  1. Clone reproduction repository:
git clone https://github.com/agentHits/next-prerender-workstore-reproduction.git
cd next-prerender-workstore-reproduction
bun install # or npm install
  1. Run a cold static export build without experimental.inlineCss: true:
rm -rf .next
bun run build # or next build
  1. On projects with standalone output and complex CSS/SCSS modules, Turbopack panics in the Rust runtime:
thread 'tokio-rt-worker' panicked at turbopack/crates/turbopack-core/src/module_graph/mod.rs:750:25:
internal error: entered unreachable code: there must be a path to a root

Debug info:
- Execution of emit_all_output_assets_once_with_issues_operation failed
- Execution of PlainIssue::from_issue failed
- Execution of <ModuleGraphImportTracer as ImportTracer>::get_traces failed
- internal error: entered unreachable code: there must be a path to a root

Current vs. Expected behavior

Current Behavior:
When formatting an issue/warning trace during CSS chunk emission (emit_all_output_assets_once_with_issues), ModuleGraphImportTracer::get_traces executes astar searching for a node with no incoming edges in the reversed graph (|n| reversed_graph.neighbors(n).next().is_none()).
If the module subgraph contains cyclic references or disconnected nodes, astar returns None, triggering the panic unreachable!("there must be a path to a root") at line 750, terminating the entire build process.

To avoid this crash, developers are forced to enable experimental.inlineCss: true, which bypasses external CSS chunking by serializing all CSS text chunks directly into the RSC Flight stream (self.__next_f), inflating document HTML size from ~150 KB to >700 KB and causing significant Core Web Vitals regressions (LCP: 8.9s vs 2.1s).

Expected Behavior:
Turbopack should handle cyclic or rootless subgraphs gracefully by falling back to returning the current module index instead of panicking.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.6.0
Binaries:
  Node: 24.20.0
  npm: 11.19.0
  Yarn: N/A
  pnpm: 11.19.0
Relevant Packages:
  next: 16.3.4 (and canary 16.4.0-canary.15)
  react: 19.2.8
  react-dom: 19.2.8
  typescript: 6.0.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack, CSS, Performance

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

A complete Rust pull request with the fix has been submitted:
👉 PR: #98204

Fix in turbopack/crates/turbopack-core/src/module_graph/mod.rs:

let path = match petgraph::algo::astar(
    &reversed_graph,
    module_idx,
    |n| reversed_graph.neighbors(n).next().is_none(),
    |e| match e.weight().chunking_type {
        ChunkingType::Parallel { .. } => 0,
        _ => 1,
    },
    |_| 0,
) {
    Some((_, path)) => path,
    None => vec![module_idx],
};

Activity

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

    CSSRelated to CSS.PerformanceAnything with regards to Next.js performance.TurbopackRelated to Turbopack with Next.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions