Jest Worker Ran Out of Memory in CI
Jest runs tests across worker processes; when total worker memory exceeds the runner RAM, a worker is OOM-killed and Jest reports it failed unexpectedly. High --maxWorkers is the usual driver.
What this error means
Tests fail with Jest worker encountered 4 child process exceptions or ran out of memory. Lowering --maxWorkers or using a larger runner clears a one-off spike; steadily climbing memory across files suggests a leak.
shell
Jest worker encountered 4 child process exceptions, exceeding retry limit
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memoryCommon causes
Too many workers for the runner RAM
Jest defaults to many workers; each holds its own heap, and the sum can exceed available memory.
A memory leak in the test setup
Unclosed handles or accumulating module state grow each worker until it is killed; that is a code fix.
How to fix it
Lower workers and cap the heap
Reduce concurrency so total worker memory fits.
shell
node --max-old-space-size=2048 node_modules/.bin/jest --maxWorkers=2Right-size or fix the leak
- Use a larger runner for genuinely heavy suites.
- Run with
--detectLeaks/--logHeapUsageto find growth. - Close DB/server handles in
afterAllto stop accumulation.
How to prevent it
- Set
--maxWorkersto the runner size. - Monitor heap usage per worker in CI.
- Right-size memory for large test suites.
Related guides
CI "JavaScript heap out of memory" (Node / V8)Fix "JavaScript heap out of memory" in CI when Node/V8 exceeds its heap limit during builds or tests. How to…
CI Step "Killed" Exit Code 137 (OOM)Why CI steps exit with code 137 and "Killed": the OOM killer sent SIGKILL after the job exceeded runner memor…
Webpack Build "heap out of memory" in CIFix a webpack build that crashes with "JavaScript heap out of memory" in CI when large bundles exhaust the V8…
Container Memory Limit Exceeded in CIFix a CI container killed for exceeding its memory limit (cgroup OOM, exit 137) even with free host RAM. How…