# Build command - JavaScript heap out of memory

**URL:** <https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348>\
**Category:** Support\
**Tags:** deployment, building\
**Created:** [February 13, 2023, 9:46am UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348 "2023-02-13T09:46:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukas123](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/lukas123/32/44847_2.png) [@lukas123](https://answers.netlify.com/u/lukas123)\
**Post date:** [February 13, 2023, 9:46am UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/1 "2023-02-13T09:46:19Z")

</div>

Hello, since last **Friday 10.02.2023** , I am not able to build the app.

- Node version: **14** and **16**
- Create React App
- Build command: **cp .env.staging .env && CI=false npm run build**
- Local building works fine

Error:

```auto
8:25:53 PM: Detected 1 framework(s)
8:25:53 PM: "create-react-app" at version "4.0.3"
8:25:53 PM: Installing missing commands
8:25:53 PM: Verify run directory
8:25:53 PM: Section completed: initializing
8:25:54 PM: ​
8:25:54 PM: Netlify Build                                                 
8:25:54 PM: ────────────────────────────────────────────────────────────────
8:25:54 PM: ​
8:25:54 PM: ❯ Version
8:25:54 PM: @netlify/build 29.5.4
8:25:54 PM: ​
8:25:54 PM: ❯ Flags
8:25:54 PM: baseRelDir: true
8:25:54 PM: buildId: 63e69a236f070f000845aa8d
8:25:54 PM: deployId: 63e69a236f070f000845aa8f
8:25:54 PM: ​
8:25:54 PM: ❯ Current directory
8:25:54 PM: /opt/build/repo
8:25:54 PM: ​
8:25:54 PM: ❯ Config file
8:25:54 PM: /opt/build/repo/netlify.toml
8:25:54 PM: ​
8:25:54 PM: ❯ Context
8:25:54 PM: production
8:25:54 PM: ​
8:25:54 PM: 1. Build command from Netlify app                             
8:25:54 PM: ────────────────────────────────────────────────────────────────
8:25:54 PM: ​
8:25:54 PM: $ cp .env.staging .env && CI=false npm run build
8:25:54 PM: > name@1.7.21 build /opt/build/repo
8:25:54 PM: > react-scripts build
8:25:55 PM: Creating an optimized production build...
8:28:32 PM: <--- Last few GCs --->
8:28:32 PM: [1401:0x5e54fb0] 156037 ms: Mark-sweep (reduce) 2030.1 (2051.0) -> 2029.0 (2052.7) MB, 656.1 / 0.0 ms (average mu = 0.222, current mu = 0.060) allocation failure scavenge might not succeed
8:28:32 PM: [1401:0x5e54fb0] 156722 ms: Mark-sweep (reduce) 2030.1 (2054.2) -> 2029.5 (2054.5) MB, 682.1 / 0.0 ms (average mu = 0.130, current mu = 0.004) allocation failure scavenge might not succeed
8:28:32 PM: <--- JS stacktrace --->
8:28:32 PM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
8:28:32 PM: 1: 0xa3ac30 node::Abort() [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 2: 0x970199 node::FatalError(char const*, char const*) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 3: 0xbba76e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 4: 0xbbaae7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 5: 0xd76d05 [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 6: 0xd7788f [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 7: 0xd856cb v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 8: 0xd8928c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 9: 0xd5796b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 10: 0x109ffbf v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 11: 0x14491d9 [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:33 PM: npm ERR! code ELIFECYCLE
8:28:33 PM: npm ERR! errno 1
8:28:33 PM: npm ERR! name@1.7.21 build: `react-scripts build`
8:28:33 PM: npm ERR! Exit status 1
8:28:33 PM: npm ERR!
8:28:33 PM: npm ERR! Failed at the name@1.7.21 build script.
8:28:33 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
8:28:33 PM: npm ERR! A complete log of this run can be found in:
8:28:33 PM: npm ERR! /opt/buildhome/.npm/_logs/2023-02-10T19_28_33_300Z-debug.log
8:28:33 PM: ​
8:28:33 PM: "build.command" failed                                        
8:28:33 PM: ────────────────────────────────────────────────────────────────
8:28:33 PM: ​
8:28:33 PM: Error message
8:28:33 PM: Command failed with exit code 1: cp .env.staging .env && CI=false npm run build (https://ntl.fyi/exit-code-1)
8:28:33 PM: ​
8:28:33 PM: Error location
8:28:33 PM: In Build command from Netlify app:
8:28:33 PM: cp .env.staging .env && CI=false npm run build
8:28:33 PM: ​
8:28:33 PM: Resolved config
8:28:33 PM: build:
8:28:33 PM: command: cp .env.staging .env && CI=false npm run build
8:28:33 PM: commandOrigin: ui
8:28:33 PM: publish: /opt/build/repo/build
8:28:33 PM: publishOrigin: ui
8:28:33 PM: redirects:
8:28:33 PM: - from: /*
      status: 200
      to: /index.html
  redirectsOrigin: config
Caching artifacts

```

---

<div class="post-metadata">

**Author:** ![SamO](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/samo/32/41847_2.png) [@SamO](https://answers.netlify.com/u/SamO)\
**Post date:** [February 13, 2023, 5:52pm UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/2 "2023-02-13T17:52:39Z")

</div>

Hi 👋🏿 @lukas123 ,

Welcome to the forums! Can you please share your site name/slug? Have you gotten this working locally first?

Finally please give [this resource](https://answers.netlify.com/t/support-guide-frequently-encountered-problems-during-builds/213) a read and see if that helps!

---

<div class="post-metadata">

**Author:** ![lukas123](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/lukas123/32/44847_2.png) [@lukas123](https://answers.netlify.com/u/lukas123)\
**Post date:** [February 13, 2023, 8:38pm UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/3 "2023-02-13T20:38:01Z")

</div>

Hello @SamO, thank you for your answer!

Site name: staging-pg-clinicy  
Yes, locally everything builds correctly.

The error is related to the draft-js library. However, I can’t tell what exactly is the problem.

Is there any way to check the build error details?

---

<div class="post-metadata">

**Author:** ![luke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/luke/32/39_2.png) [@luke](https://answers.netlify.com/u/luke)\
**Post date:** [February 16, 2023, 2:21am UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/6 "2023-02-16T02:21:06Z")

</div>

Hi, @lukas123. We checked the memory use for that build and it didn’t exceed Netlify’s memory limits. However, it clearly is exceeding the default limits of node.js based on this:

```plaintext
8:28:32 PM: <--- Last few GCs --->
8:28:32 PM: [1401:0x5e54fb0] 156037 ms: Mark-sweep (reduce) 2030.1 (2051.0) -> 2029.0 (2052.7) MB, 656.1 / 0.0 ms (average mu = 0.222, current mu = 0.060) allocation failure scavenge might not succeed
8:28:32 PM: [1401:0x5e54fb0] 156722 ms: Mark-sweep (reduce) 2030.1 (2054.2) -> 2029.5 (2054.5) MB, 682.1 / 0.0 ms (average mu = 0.130, current mu = 0.004) allocation failure scavenge might not succeed
8:28:32 PM: <--- JS stacktrace --->
8:28:32 PM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
8:28:32 PM: 1: 0xa3ac30 node::Abort() [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 2: 0x970199 node::FatalError(char const*, char const*) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 3: 0xbba76e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 4: 0xbbaae7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 5: 0xd76d05 [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 6: 0xd7788f [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 7: 0xd856cb v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 8: 0xd8928c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 9: 0xd5796b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 10: 0x109ffbf v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]
8:28:32 PM: 11: 0x14491d9 [/opt/buildhome/.nvm/versions/node/v14.21.2/bin/node]

```

Your javascript (node) heap ran out of memory. You can increase it by adding an environment variable here:

[https://app.netlify.com/sites/staging-pg-clinicy/settings/env](https://app.netlify.com/sites/staging-pg-clinicy/settings/env)

Please click the “Migrate environment variables” button and then add an environment variable named `NODE_OPTIONS` with a value of `--max-old-space-size=4096` like so:

 ![image](https://global.discourse-cdn.com/netlify/original/3X/1/3/1333c113fb5115bc2e45b87d526ea2c998d60608.png)

Create the variable to save it and now trigger a new deploy. This time node should run but allow more memory to be used for the javascript heap. This will hopefully resolve the “JavaScript heap out of memory” error.

​Please let us know if that works for you or not. If there are other questions, please feel free to share them here anytime.

---

<div class="post-metadata">

**Author:** ![cantkillemall](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/cantkillemall/32/54039_2.png) [@cantkillemall](https://answers.netlify.com/u/cantkillemall)\
**Post date:** [August 26, 2023, 6:27pm UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/7 "2023-08-26T18:27:25Z")

</div>

Hi @luke,

I had the exact same error when building, I tried your tip just above, but I still have the same build error.

 ![Capture d’écran 2023-08-26 à 20.23.56](https://global.discourse-cdn.com/netlify/original/3X/5/f/5ffc9f2f1809d864f396e936df6c87925feeba31.png)

Could you please check my site (bigbangmag-beta) and let me know? Am I still over the memory limits?  
Thank you!

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [August 26, 2023, 6:55pm UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/8 "2023-08-26T18:55:36Z")

</div>

@cantkillemall, yours is a case of: [JavaScript heap out of memory when trying to build a Nuxt app](https://answers.netlify.com/t/93138)

---

<div class="post-metadata">

**Author:** ![cantkillemall](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/cantkillemall/32/54039_2.png) [@cantkillemall](https://answers.netlify.com/u/cantkillemall)\
**Post date:** [August 27, 2023, 8:32am UTC](https://answers.netlify.com/t/build-command-javascript-heap-out-of-memory/85348/9 "2023-08-27T08:32:57Z")

</div>

OMG, this one hasn’t come up in my search results!!  
Problem solved, huge thanks @hrishikesh
