Build command - JavaScript heap out of memory

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:

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

Hi :wave:t6: @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 a read and see if that helps!

1 Like

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?

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:

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

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:

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.

Hi @luke,

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

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

@cantkillemall, yours is a case of: JavaScript heap out of memory when trying to build a Nuxt app

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