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.
<--- 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
- Set
NODE_OPTIONS=--max-old-space-size=4096for the test step. - Reduce worker count so total memory fits the runner.
- Re-run and watch peak memory drop below the limit.
env:
NODE_OPTIONS: --max-old-space-size=4096Use a single-fork or limited pool
Fewer workers can lower peak memory even if slower; combine with the fix above.
vitest run --pool=forks --poolOptions.forks.maxForks=2How to prevent it
- Set a sensible
--max-old-space-sizefor large suites. - Cap worker count to the runner memory budget.
- Clean up module-level state and large fixtures between tests.