Increase the Node.js heap memory limit
Low risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Raises the V8 old-space heap ceiling for Node.js processes in the current shell, fixing "JavaScript heap out of memory" crashes in large builds.
nodememoryheapbuild
Parameters
Maximum old-space heap size in megabytes.
Commands
Show the current default heap limit
node -e "console.log(require('v8').getHeapStatistics().heap_size_limit / 1048576, 'MB')"Raise the heap limit for all node processes started from this shell
export NODE_OPTIONS="--max-old-space-size=4096"Verification
node -e "console.log(require('v8').getHeapStatistics().heap_size_limit / 1048576, 'MB')"The printed limit reflects the requested size.
Undo
Remove the override; new node processes revert to the default limit
unset NODE_OPTIONSPitfalls
- The setting lasts only for the current shell session; put it in the specific npm script (node --max-old-space-size=...) for a permanent fix.
- Raising the limit beyond physical RAM trades a crash for swapping and system-wide slowdown.
- Frequent out-of-memory errors in a modest project usually indicate a leak or a misconfigured build, not a genuinely large heap requirement.