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

Turbopack Build Saturates 4 GB And Stalls Or OOMs On Large Module Graphs

Next.js Turbopack production build consumes the entire 4 GB container memory when compiling ~12,000 client modules, causing continuous cgroup limit hits and either a kernel OOM kill or a timeout without forward progress. The issue affects 16.3.2 and 16.4.0-canary.4.

highConfidence 65%Next.jsRoute Handlersnext buildAffected V16.3.2Affected V16.4.0-Canary.4

Origin Analysis

Turbopack's production build retains the entire module graph and intermediate compilation artifacts in memory simultaneously, and fails to evict or stream under memory pressure. With 12,000 deterministic client modules, peak usage exceeds the 4 GiB cgroup ceiling, leading to constant at-limit reclaim attempts and no observable progress.
1. Clone https://github.com/shunkakinoki/next-turbopack-build-memory-reproduction 2. Run `bun install --frozen-lockfile --minimum-release-age=0` 3. Run `bun run reproduce -- canary` (or `-- 16.3.2`) This generates 100 App Router routes and 12,000 client modules (79.8 MiB), then runs `next build` in a 2 CPU / 4 GB memory cgroup. The build stalls in 'Creating an optimized production build ...' and gets killed or times out.

Fixing Code Block

Edge Case Audit

This config may cause Turbopack to fail earlier with an out-of-memory error, which is preferable to a kernel kill but still aborts the build. The underlying memory retention remains. If `turbopackMemoryLimit` is not honored in your Next.js version, the build will still saturate the cgroup. Reducing `cpus` significantly slows the build. Roll back by removing the experimental keys. Test on your exact version and workload before adopting in CI.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state