# FATAL ERROR: JavaScript heap out of memory How to fix it.

URL: https://antideploy.com/blog/javascript-heap-out-of-memory-during-the-build

Node ran out of memory during the build. This usually means a very large bundle. Shrink it, or raise Node's memory limit in the build script.

**What you see**

```
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of
memory
<--- Last few GCs --->
```

## At a glance

- **What it means**: Node ran out of memory
- **Fix one**: Shrink the bundle
- **Fix two**: Raise Node's memory limit
- **Look for**: A dependency you do not need

Published 7 October 2026. Facts checked 7 October 2026. 1 min read.

## What it means

Node.js limits how much memory a process can use. During your build, a step grew past that limit and stopped. This usually means a very large bundle: many files, large images imported as code, or a package pulled in that does not need to be.

## How to fix it

### 1. Remove what you do not need

Look for a large dependency that is imported only for one small use, large data files imported into code, or a whole library imported instead of one function.

### 2. Raise Node's memory limit in the build script

Set `NODE_OPTIONS=--max-old-space-size` in your build script. The number is in megabytes.

**package.json**

```
{
  "scripts": {
    "build": "NODE_OPTIONS=--max-old-space-size=4096 next build"
  }
}
```

### 3. Build again

The build server has a limited amount of memory, so raising the limit only helps up to what it has. A smaller bundle is the more reliable fix.

## Memory questions, answered.

Anything else? Write to us and a person answers.

[support@antideploy.com](mailto:support@antideploy.com)

### Why does it only fail online?

Your computer may have more memory available to the build than the build server has.

### Is this the same as the app running out of memory?

No. This is the build. If the app runs out of memory while it runs, see [the app ran out of memory while starting](https://antideploy.com/blog/app-ran-out-of-memory-while-starting).

### Does this failed deploy cost anything?

No. Failed deploys never count against your plan.

## More guides, and the platform.

Each platform page covers one part of Antideploy: what it does, where it stops and the questions people ask. [See the whole platform](https://antideploy.com/platform), or [all the guides](https://antideploy.com/blog).

- [Next.js build worker exited with code: 1](https://antideploy.com/blog/nextjs-build-worker-exited-with-code-1): The build worker crashed. Read the lines above for the file, run the build locally, and check memory.
- [The build ran out of time](https://antideploy.com/blog/build-ran-out-of-time): Builds are given 20 minutes. A step is probably hanging, such as a watch mode or a long compile.
- [Your app ran out of memory while starting up](https://antideploy.com/blog/app-ran-out-of-memory-while-starting): Each app has 1 GB, a Java app 2 GB. Loading a large model or dataset at startup can use it all. Load lazily.

- [Deployments](https://antideploy.com/platform/deployments)
- [Logs and monitoring](https://antideploy.com/platform/logs-and-monitoring)
- [Hosting](https://antideploy.com/platform/hosting)

Facts on this page were checked against the live platform on 7 October 2026.

## Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

To set this up, give your coding agent this sentence:

```text
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
```
