A build or test run needs more than the default limit
CommonBundlers, type checkers and test runners on a large project can legitimately need more heap than a small CI runner's default gives.
Confirm
node -p "Math.round(require('v8').getHeapStatistics().heap_size_limit / 1048576) + ' MB'"The limit on the machine that fails, compared with the one that works
Fix
- Raise the limit for the job, below the memory the machine or container really has: NODE_OPTIONS=--max-old-space-size=3072 npm run build.
- On Node 22 and 24 you can give a share of memory instead: NODE_OPTIONS=--max-old-space-size-percentage=75. Node 20's documentation does not list it, and Node 18 rejects it as a bad option.
- Run fewer workers at once (tests, parallel builds); each worker is a process with its own heap.
NODE_OPTIONS=--max-old-space-size=3072 npm run build
NODE_OPTIONS reaches the node processes npm starts: through npm run on Node.js 25.9.0 (npm 11.12.1), the script's node reported 3264 MB, against 4288 MB without it.