Node.js "spawn ENOMEM" in CI - Out of Memory to Start a Child
Node failed to spawn a child process with ENOMEM. child_process.spawn/exec forks the runtime, and under memory pressure the kernel cannot back the new process - so the spawn is refused before the child ever runs.
What this error means
A Node tool fails with Error: spawn ENOMEM or errno: -12, code: 'ENOMEM', syscall: 'spawn'. It happens at the moment a child process is launched (a sub-command, a worker, a git call), not during the parent’s own work.
Error: spawn ENOMEM
at ChildProcess.spawn (node:internal/child_process)
errno: -12, code: 'ENOMEM', syscall: 'spawn git'Common causes
The runner is under memory pressure
Node forks (copy-on-write) to spawn a child. When free memory is low, the kernel cannot reserve the new process’s pages and returns ENOMEM, failing the spawn.
A large parent process makes every fork expensive
A Node process holding a big heap makes each fork’s reservation larger. With strict overcommit or a tight cgroup, spawning a child from a heavy parent is what tips it over.
How to fix it
Confirm memory and cap the heap
Check free memory, then bound Node’s heap so the parent leaves room to fork.
free -m
export NODE_OPTIONS=--max-old-space-size=2048Reduce pressure or add RAM
- Move the job to a runner with more memory.
- Lower concurrency (fewer workers/forks at once) so peak memory is lower.
- Spawn children before the parent grows its heap, where you control the ordering.
How to prevent it
- Cap
--max-old-space-sizebelow the runner ceiling so forks have headroom. - Size runners for the peak of parent plus spawned children.
- Bound the number of concurrent child processes.