Skip to content
Nilay Kabariya

Entry No.071·Fixes··2 min read

Fix: JavaScript heap out of memory (Node.js, tested)

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory. Default limits measured, and two ways the usual fix silently fails.

The error, verbatim

Jump to the fix ↓
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
✓ Reproduced on Windows 11 Pro, 11.8 GB RAM

Tested on

Node
24.14.0 / 26.11.1
npm
11.9.0
OS
Windows 11 Pro, 11.8 GB RAM
Contents
  1. The fix: NODE_OPTIONS01
  2. Why the usual fix sometimes doesn’t work02
  3. Two surprises in the numbers03
  4. How this was tested04

Node gives JavaScript a fixed amount of memory, the heap limit. A big build, a large test run or a script that keeps too much in memory hits it, and the process dies with exit code 134:

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

The limit isn’t your RAM. On my laptop with 11.8 GB, the default was:

Node Default heap limit
24.14.0 2,240 MB
26.11.1 2,144 MB

You can check yours with node -e "console.log(require('v8').getHeapStatistics().heap_size_limit/2**20)".

Raising it is one setting, --max-old-space-size (in MB). How you pass it decides whether it actually reaches the process that runs out.

The fix: NODE_OPTIONS

Set it through the NODE_OPTIONS environment variable. In PowerShell:

$env:NODE_OPTIONS = "--max-old-space-size=4096"

Then run your build or tests in the same window. In an npm script, use cross-env so it works on Windows too:

"build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 vite build"

Pick a number below your free RAM: 4096 is a common choice on 8 to 16 GB machines.

Why the usual fix sometimes doesn’t work

Two surprises in the numbers

The limit you ask for isn’t the limit you get: --max-old-space-size=1024 gave a heap limit of 1,216 MB and =256 gave 448 MB. The flag sets the “old space”; Node adds its young generation on top.

Node also doesn’t check the number against your RAM. --max-old-space-size=100000 on this 11.8 GB laptop was accepted without a warning (limit: 100,192 MB). So a number above your RAM doesn’t fail fast; keep it below what the machine actually has.

How this was tested

Windows 11 Pro with 11.8 GB RAM, Node 24.14.0 and 26.11.1, npm 11.9.0, October 17, 2026. A script allocated arrays in a loop until it crashed or reached a set amount; the heap limit was read with v8.getHeapStatistics() in the script and in a child process it started with child_process. The npm script cases ran through npm run (which uses cmd.exe), cross-env 10.1.0, and PowerShell 5.1. Every message above is the real output.

— N.K., end of entry No.071

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.016

    Fix: 'vite' is not recognized as an internal or external command

    Windows says the command doesn't exist, but it's right there in node_modules. Five causes, how to tell them apart in one command, and what each one needs.

    > 'vite' is not recognized as an internal or external command,

    FIXED5 minWindows
  2. No.093

    Fix: bigint Failed to load bindings, pure JS will be used

    bigint: Failed to load bindings, pure JS will be used. Why npm 12 shows it on every install, whether it matters, and how to get the native build back.

    > bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)

    FIXED3 minWindows
  3. No.072

    npm error code ENOENT, and spawn npx ENOENT on Windows

    Read the path line first. On Windows, spawn npx ENOENT has a twist: adding .cmd now fails with EINVAL. Four ENOENT causes reproduced, each with its fix.

    > npm error code ENOENT

    FIXED3 minWindows
  4. No.069

    Fix: EBUSY: resource busy or locked (npm, Windows)

    npm install and Node fail on Windows with EBUSY: resource busy or locked, rmdir. Reproduced: what holds the folder, how to find it, and why retrying fails.

    > npm error code EBUSY

    FIXED3 minWindows

Post card · Every Sunday

What broke this week.

One email on Sundays: the Node, TypeScript, Python and AI SDK releases that broke builds that week, each one reproduced, with a link to the fix that worked. Never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text