Common causes
- Building a large application with webpack or other bundlers that process many modules
- A memory leak — objects are being created but never garbage collected
- Processing large data files or arrays in memory all at once
- Running Node.js in a container with very limited memory allocation
How to fix it
- Increase the Node.js memory limit: NODE_OPTIONS='--max-old-space-size=4096' npm run build
- Add it permanently to your npm script: "build": "node --max-old-space-size=4096 node_modules/.bin/webpack"
- Profile memory usage to find leaks: node --inspect index.js and use Chrome DevTools
- Process large data in streams or chunks instead of loading everything into memory
Example
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
<--- Last few GCs --->
[12345:0x...] Scavenge (reduce) 1500.0 / 1500.0 msRunning npm run build on a large Next.js or webpack application without increasing the memory limit
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
