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

Next.Js Build Workers Strip --Max-Old-Space-Size And OOM During Page-Data Collection

Next.js 16.3.0-preview.5 strips the --max-old-space-size Node flag from build workers when isolatedMemory is true, leaving no memory bound for page-data collection. Large module graphs cause worker SIGKILL, independent of bundler (Turbopack or Webpack).

highConfidence 85%Next.jsAffected V16.3.0-Preview.5

Origin Analysis

In createStaticWorker (packages/next/src/build/index.ts) isolatedMemory: true causes the Worker wrapper (packages/next/src/lib/worker.ts) to delete nodeOptions['max-old-space-size'], so NODE_OPTIONS heap cap is ignored. jest-worker's workerIdleMemoryLimit is not wired through, resulting in unbounded worker memory and OOM kill.
Clone the repo at https://github.com/alexboii/next-build-worker-oom. Run: docker run --rm -m 4g --cpus 4 -v $PWD:/app -w /app node:22 bash -c 'npm install --no-audit --no-fund && npx next build'. Observe SIGKILL during Collecting page data. Try NODE_OPTIONS=--max-old-space-size=1024 and observe same result. Set experimental.cpus:1 and the build passes.

Fixing Code Block

Edge Case Audit

Setting the cap too low may cause workers to crash with JS heap out of memory during page-data collection, leaving the build in a partial state. The env var is undocumented and may be removed in future versions; do not rely on it long-term. Test thoroughly in your CI before rolling out. To rollback, unset NEXT_WORKER_MAX_OLD_SPACE_SIZE and revert the patch.

Ecosystem Topology