Node.js JavaScript heap out of memory
April 30, 2026 · View on GitHub
Playbook ID: node-out-of-memory
Category: build
Severity: high
Tags: node, javascript, webpack, nextjs, oom, heap, memory
What this failure means
The Node.js process ran out of heap memory during the build. This is common in large Webpack, Next.js, or Jest builds where the default V8 heap limit is too low for the amount of modules being processed.
Common log signals
FATAL ERROR: Reached heap limit Allocation failed
JavaScript heap out of memory
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed
Ineffective mark-compacts near heap limit
<--- Last few GCs --->
<--- JS stacktrace --->
Allocation failed - JavaScript heap out of memory
ERR_WORKER_OUT_OF_MEMORY
Diagnosis
The Node.js process ran out of heap memory during the build. This is common in large Webpack, Next.js, or Jest builds where the default V8 heap limit is too low for the amount of modules being processed.
Fix steps
- Increase the Node.js heap limit: set
NODE_OPTIONS=--max-old-space-size=4096(or higher) before the build command. - For npm scripts, add it inline in package.json scripts:
"build": "NODE_OPTIONS=--max-old-space-size=4096 next build". - For Jest OOM: pass
--maxWorkers=2or--runInBandto serialize test execution and lower peak memory. - Upgrade the CI runner to a higher-memory tier — heap expansion is not free; more RAM is the most reliable fix.
- Identify the heap consumer: add
--inspector runnode --max-old-space-size=2048 --trace-gcand profile with Chrome DevTools. - Break the build into smaller increments (e.g., build packages individually in a monorepo).
Validation
- Re-run the local reproduction command after the fix.
- NODE_OPTIONS=--max-old-space-size=4096 npm run build
Likely files to inspect
package.jsonwebpack.config.jsnext.config.jsjest.config.js
Run Faultline
faultline analyze build.log
faultline explain node-out-of-memory
faultline workflow build.log --json --mode agent
Search phrases this page answers
- Node.js JavaScript heap out of memory
- Build: node.js javascript heap out of memory
- FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed
- GitHub Actions node.js javascript heap out of memory
- faultline explain node-out-of-memory
- Node.js node.js javascript heap out of memory
Generated from playbooks/bundled/log/build/node-out-of-memory.yaml. Do not edit directly — run make docs-generate.