Skip to content
Latchkey

Vitest "JavaScript heap out of memory" in CI

V8 hit its heap ceiling and aborted. Large suites, many concurrent workers each holding modules, or memory leaks in tests push CI over the default limit. Raise the limit via NODE_OPTIONS, reduce worker count, or use the forks pool.

What this error means

The run dies with "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory" and exit code 134, often as the suite grows.

Terminal
<--- Last few GCs --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x... node::Abort()
Error: Process completed with exit code 134.

Common causes

The default heap is too small for the suite

Large module graphs across many workers exceed the default V8 old-space limit on a modest runner.

Too many workers multiply memory use

Each pool worker loads its own copy of modules; high concurrency multiplies memory until the runner is exhausted.

How to fix it

Raise the heap and control concurrency

  1. Set NODE_OPTIONS=--max-old-space-size=4096 for the test step.
  2. Reduce worker count so total memory fits the runner.
  3. Re-run and watch peak memory drop below the limit.
.github/workflows/ci.yml
env:
  NODE_OPTIONS: --max-old-space-size=4096

Use a single-fork or limited pool

Fewer workers can lower peak memory even if slower; combine with the fix above.

Terminal
vitest run --pool=forks --poolOptions.forks.maxForks=2

How to prevent it

  • Set a sensible --max-old-space-size for large suites.
  • Cap worker count to the runner memory budget.
  • Clean up module-level state and large fixtures between tests.

Related guides

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