Skip to content
Latchkey

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.

CI log
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.

Terminal
free -m
export NODE_OPTIONS=--max-old-space-size=2048

Reduce pressure or add RAM

  1. Move the job to a runner with more memory.
  2. Lower concurrency (fewer workers/forks at once) so peak memory is lower.
  3. Spawn children before the parent grows its heap, where you control the ordering.

How to prevent it

  • Cap --max-old-space-size below the runner ceiling so forks have headroom.
  • Size runners for the peak of parent plus spawned children.
  • Bound the number of concurrent child processes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →