## TL;DR

Cypress runs the browser and the test runner in one process tree, and large suites exhaust the heap. Raise the Node memory limit, split the run into smaller chunks, and look for specs that leak memory across tests.

## Error

```text
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
```

## Steps

1. Confirm it is Cypress and not the app: the crash message names the Cypress process, and small specs pass. Expected: you rule out the application.
2. Raise the memory limit for the Cypress process: `NODE_OPTIONS=--max-old-space-size=4096 npx cypress run`. Expected: the run gets further before any crash.
3. Split the suite: run specs in groups (`--spec "cypress/e2e/a/**"`, then `b/**`). Expected: each chunk fits comfortably in memory.
4. Find leaking specs: run each spec file alone and watch memory; a spec whose memory never drops between tests is the culprit. Expected: one or two specs stand out.
5. Fix the leak: usually unclosed intercepts, huge fixtures loaded per test, or DOM retained by aliases. Expected: the spec's memory returns to baseline after each test.

## When to use

- `JavaScript heap out of memory` naming the Cypress or Electron process.
- Suites with hundreds of specs or very large fixtures.

## When not to use

- Jest heap OOM (different process model; see that skill).
- The app under test runs out of memory (check the app's own logs).

## Tool compatibility

- Cypress 10 through 14; `NODE_OPTIONS` respected by the Cypress CLI.

## Variant phrasings

### Cypress crashed with SIGKILL in CI

CI OOM-killer, same root cause; check runner memory limits, not just Node flags.

### Allocation failed during cypress run

The long form of the heap error; the fix is identical.

## Why it happens

Each spec file loads fixtures, plugins, and support files into the same long-lived process. Memory grows across specs and the default heap limit is too small for big suites.

## Edge cases

- Raising the heap without splitting just delays the crash on truly huge suites.
- `numTestsKeptInMemory` controls how many test snapshots Cypress retains; lowering it cuts memory a lot.
- Videos held in memory during the run also count; disabling video for passes helps.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_6nusfTqtHsSk4fIXUiawdA
