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

I cannot resolve issue :(, my project using use nuxt 3
My site: littlespace.vn

> 9:27:10 AM: Packaging Functions from .netlify/functions-internal directory:
> 9:27:10 AM:  - server/server.mjs
> 9:27:10 AM: ​
> 9:27:55 AM: <--- Last few GCs --->
> 9:27:55 AM: [4079:0x5e77430]    57413 ms: Mark-sweep 4052.5 (4133.9) -> 4052.5 (4133.9) MB, 4471.6 / 0.0 ms  (average mu = 0.165, current mu = 0.015) allocation failure; scavenge might not succeed
> 9:27:55 AM: [4079:0x5e77430]    63098 ms: Mark-sweep 4068.2 (4133.9) -> 4068.2 (4165.9) MB, 5678.0 / 0.0 ms  (average mu = 0.077, current mu = 0.001) allocation failure; scavenge might not succeed
> 9:27:55 AM: <--- JS stacktrace --->
> 9:27:55 AM: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
> 9:27:55 AM:  1: 0xb7a940 node::Abort() [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  2: 0xa8e823  [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  3: 0xd5c990 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  4: 0xd5cd37 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  5: 0xf3a435  [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  6: 0xf4c91d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  7: 0xf2701e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  8: 0xf283e7 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/buildhome/node-deps/node]
> 9:27:55 AM:  9: 0xf095ba v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/opt/buildhome/node-deps/node]
> 9:27:55 AM: 10: 0x12ce7ff v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/opt/buildhome/node-deps/node]
> 9:27:55 AM: 11: 0x16fb6f9  [/opt/buildhome/node-deps/node]
> 9:27:59 AM: /opt/build-bin/build: line 126:  4079 Aborted                 (core dumped) FORCE_COLOR=1 $netlify_build_node_bin $netlify_build_bin --cwd=$repository_root --repositoryRoot=$repository_root --config=$configuration_file_path --branch=$branch --siteId=$site_id --defaultConfig=$default_config --baseRelDir=$base_rel_dir --context=$context --node-path=$user_node_path --cachedConfigPath=$cached_netlify_build_config_file --api-host=$netlify_endpoint --token=$netlify_token --build-id=$BUILD_ID --deploy-id=$DEPLOY_ID --mode=buildbot --telemetry=$build_telemetry --send-status --save-config --statsd.host=$HOST_NODE_IP --statsd.port=$STATSD_PORT --tracing.enabled=$tracing_enabled --tracing.host=$HOST_NODE_IP --tracing.traceId=$trace_id --tracing.parentSpanId=$parent_span_id --tracing.traceFlags=$trace_flags --functions-dist-dir=$functions_dist_dir --edge-functions-dist-dir=$edge_functions_dist_dir --cache-dir=$cache_dir --buildbot-server-socket=$buildbot_server_socket --framework=$framework --feature-flags=$feature_flags --testOpts.silentLingeringProcesses=$SILENT_LINGERING_PROCESSES --system-log-file=$system_log_file --explicit-secret-keys=$explicit_secret_keys
> 9:28:44 AM: Failed during stage 'building site': Build script returned non-zero exit code: 134 (https://ntl.fyi/exit-code-134)
> 9:28:44 AM: Error running command: Build script returned non-zero exit code: 134
> 9:28:44 AM: Failing build: Failed to build site
> 9:28:44 AM: Finished processing build request in 2m31.308s

@glorfindel9 You’re running out of memory.

If you’re doing something that you know to be intensive you should look at optimizing it.

can i increase heap memory size?

@glorfindel9 There’s some limited capability for adjustment, see the support guide here:

1 Like

I don’t know how to fix it one build goes ok and next one faild and it last for three days now. I change almost nothing in my code. Please help

11:58:32 AM: success Building production JavaScript and CSS bundles - 27.161s
11:59:02 AM: <--- Last few GCs --->
11:59:02 AM: [3922:0x6de7ba0]    85135 ms: Scavenge (reduce) 1895.5 (2080.4) -> 1895.4 (2081.6) MB, 4.3 / 0.0 ms  (average mu = 0.210, current mu = 0.220) allocation failure;
11:59:02 AM: [3922:0x6de7ba0]    85142 ms: Scavenge (reduce) 1896.6 (2081.6) -> 1896.5 (2082.6) MB, 4.9 / 0.0 ms  (average mu = 0.210, current mu = 0.220) allocation failure;
11:59:02 AM: [3922:0x6de7ba0]    85148 ms: Scavenge (reduce) 1897.5 (2082.6) -> 1897.4 (2083.6) MB, 4.7 / 0.0 ms  (average mu = 0.210, current mu = 0.220) allocation failure;
11:59:02 AM: <--- JS stacktrace --->
11:59:02 AM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
11:59:02 AM:  1: 0xb87bc0 node::Abort() [node]
11:59:02 AM:  2: 0xa96834  [node]
11:59:02 AM:  3: 0xd687f0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
11:59:02 AM:  4: 0xd68b97 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
11:59:02 AM:  5: 0xf462a5  [node]
11:59:02 AM:  6: 0xf471a8 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
11:59:02 AM:  7: 0xf576b3  [node]
11:59:02 AM:  8: 0xf58528 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
11:59:02 AM:  9: 0xf32e8e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
11:59:02 AM: 10: 0xf34257 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
11:59:02 AM: 11: 0xf147a0 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
11:59:02 AM: 12: 0xf0c214 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [node]
11:59:02 AM: 13: 0xf0e5a8 v8::internal::FactoryBase<v8::internal::Factory>::NewRawTwoByteString(int, v8::internal::AllocationType) [node]
11:59:02 AM: 14: 0x133ff6c v8::internal::IncrementalStringBuilder::Extend() [node]
11:59:02 AM: 15: 0x1055450 v8::internal::JsonStringifier::SerializeString(v8::internal::Handle<v8::internal::String>) [node]
11:59:02 AM: 16: 0x10568f1 v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<true>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [node]
11:59:02 AM: 17: 0x105ad2f v8::internal::JsonStringifier::Result v8::internal::JsonStringifier::Serialize_<false>(v8::internal::Handle<v8::internal::Object>, bool, v8::internal::Handle<v8::internal::Object>) [node]
11:59:02 AM: 18: 0x105ba7f v8::internal::JsonStringify(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [node]
11:59:02 AM: 19: 0xdee7a7 v8::internal::Builtin_JsonStringify(int, unsigned long*, v8::internal::Isolate*) [node]
11:59:02 AM: 20: 0x170a179  [node]
11:59:04 AM: Aborted (core dumped)
11:59:04 AM: ​
11:59:04 AM: build.command failed                                        
11:59:04 AM: ────────────────────────────────────────────────────────────────
11:59:04 AM: ​
11:59:04 AM:   Error message
11:59:04 AM:   Command failed with exit code 134: npm run build (https://ntl.fyi/exit-code-134)
11:59:04 AM: ​
11:59:04 AM:   Error location
11:59:04 AM:   In Build command from Netlify app:
11:59:04 AM:   npm run build
11:59:04 AM: ​
11:59:04 AM:   Resolved config
11:59:04 AM:   build:
11:59:04 AM:     command: npm run build
11:59:04 AM:     commandOrigin: ui
11:59:04 AM:     environment:
11:59:04 AM:       - GATSBY_DISQUS_NAME
11:59:04 AM:       - REGIONS_ALLOWED
11:59:04 AM:       - WPGRAPHQL_URL
11:59:04 AM:       - YOUTUBE_DATA_API_V3_API_KEY
11:59:04 AM:     publish: /opt/build/repo/public
11:59:04 AM:     publishOrigin: ui
11:59:04 AM:   plugins:
11:59:04 AM:     - inputs: {}
11:59:04 AM:       origin: ui
11:59:04 AM:       package: '@netlify/plugin-gatsby'
11:59:04 AM:     - inputs: {}
11:59:04 AM:       origin: ui
11:59:04 AM:       package: '@netlify/plugin-lighthouse'
11:59:04 AM:   redirects:
11:59:06 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:59:06 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:59:06 AM: Failing build: Failed to build site
11:59:07 AM: Finished processing build request in 2m32.761s

can you share the link to your site?

Sure here it is:

I have encountered a similar problem:

3:14:45 PM: build-image version: 6c108058a8eab898e5e003ecad67a8f5f2f8c0bc (focal)
3:14:45 PM: buildbot version: 1e933903082ddddf955fd2397e5d98197c8a8b2b
3:14:45 PM: Fetching cached dependencies
3:14:45 PM: Starting to download cache of 511.1MB
3:14:56 PM: Finished downloading cache in 10.59s
3:14:56 PM: Starting to extract cache
3:14:59 PM: Finished extracting cache in 3.533s
3:14:59 PM: Finished fetching cache in 14.205s
3:14:59 PM: Starting to prepare the repo for build
3:14:59 PM: Preparing Git Reference refs/heads/main
3:15:01 PM: Starting to install dependencies
3:15:01 PM: Python version set to 3.8
3:15:01 PM: Attempting Ruby version 2.7.2, read from environment
3:15:02 PM: Using Ruby version 2.7.2
3:15:02 PM: Started restoring cached go cache
3:15:02 PM: Finished restoring cached go cache
3:15:02 PM: go version go1.19.13 linux/amd64
3:15:03 PM: Using PHP version 8.0
3:15:03 PM: Started restoring cached Node.js version
3:15:04 PM: Finished restoring cached Node.js version
3:15:04 PM: Downloading and installing node v18.18.2...
3:15:04 PM: Downloading https://nodejs.org/dist/v18.18.2/node-v18.18.2-linux-x64.tar.xz...
3:15:05 PM: Computing checksum with sha256sum
3:15:05 PM: Checksums matched!
3:15:07 PM: Enabling Node.js Corepack
3:15:07 PM: Started restoring cached build plugins
3:15:07 PM: Finished restoring cached build plugins
3:15:07 PM: Started restoring cached corepack dependencies
3:15:07 PM: Finished restoring cached corepack dependencies
3:15:07 PM: No npm workspaces detected
3:15:07 PM: Started restoring cached node modules
3:15:07 PM: Finished restoring cached node modules
3:15:07 PM: Installing npm packages using npm version 9.8.1
3:15:10 PM: up to date, audited 924 packages in 3s
3:15:10 PM: 5 vulnerabilities (2 moderate, 2 high, 1 critical)
3:15:10 PM: To address all issues, run:
3:15:10 PM:   npm audit fix
3:15:10 PM: Run `npm audit` for details.
3:15:10 PM: npm packages installed
3:15:10 PM: Install dependencies script success
3:15:10 PM: Starting build script
3:15:11 PM: Detected 1 framework(s)
3:15:11 PM: "vuepress" at version "2.0.0-beta.61"
3:15:11 PM: Section completed: initializing
3:15:13 PM: ​
3:15:13 PM: Netlify Build                                                 
3:15:13 PM: ────────────────────────────────────────────────────────────────
3:15:13 PM: ​
3:15:13 PM: ❯ Version
3:15:13 PM:   @netlify/build 29.24.0
3:15:13 PM: ​
3:15:13 PM: ❯ Flags
3:15:13 PM:   baseRelDir: true
3:15:13 PM:   buildId: 653b636346654b256764bca2
3:15:13 PM:   deployId: 653b636346654b256764bca4
3:15:13 PM: ​
3:15:13 PM: ❯ Current directory
3:15:13 PM:   /opt/build/repo
3:15:13 PM: ​
3:15:13 PM: ❯ Config file
3:15:13 PM:   No config file was defined: using default values.
3:15:13 PM: ​
3:15:13 PM: ❯ Context
3:15:13 PM:   production
3:15:13 PM: ​
3:15:13 PM: ❯ Loading plugins
3:15:13 PM:    - @netlify/plugin-lighthouse@4.1.1 from Netlify app
3:15:13 PM: ​
3:15:13 PM: ❯ Outdated plugins
3:15:13 PM:    - @netlify/plugin-lighthouse@4.1.1: latest version is 5.0.0
3:15:13 PM:      To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (https://app.netlify.com/plugins)
3:15:14 PM: ​
3:15:14 PM: Build command from Netlify app                                
3:15:14 PM: ────────────────────────────────────────────────────────────────
3:15:14 PM: ​
3:15:14 PM: $ npm run docs:build
3:15:14 PM: > vuepress-theme-hope-template@2.0.0 docs:build
3:15:14 PM: > vuepress build docs
3:15:16 PM: - Initializing and preparing data
3:15:24 PM: βœ” Initializing and preparing data - done in 8.19s
3:15:24 PM: - Compiling with vite
3:15:35 PM: Browserslist: caniuse-lite is outdated. Please run:
3:15:35 PM:   npx update-browserslist-db@latest
3:15:35 PM:   Why you should do it regularly: https://github.com/browserslist/update-db#readme
3:16:11 PM: <--- Last few GCs --->
3:16:11 PM: [3749:0x6a17c00]    56725 ms: Scavenge 1977.4 (2067.8) -> 1975.2 (2068.3) MB, 3.7 / 0.0 ms  (average mu = 0.872, current mu = 0.586) allocation failure;
3:16:11 PM: [3749:0x6a17c00]    56739 ms: Scavenge 1985.4 (2073.6) -> 1983.9 (2091.6) MB, 5.3 / 0.0 ms  (average mu = 0.872, current mu = 0.586) allocation failure;
3:16:11 PM: [3749:0x6a17c00]    57249 ms: Mark-sweep 1988.9 (2094.0) -> 1977.2 (2097.4) MB, 501.4 / 0.0 ms  (average mu = 0.776, current mu = 0.393) allocation failure; scavenge might not succeed
3:16:11 PM: <--- JS stacktrace --->
3:16:11 PM: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
3:16:11 PM:  1: 0xb85bc0 node::Abort() [node]
3:16:11 PM:  2: 0xa94834  [node]
3:16:11 PM:  3: 0xd66d10 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
3:16:11 PM:  4: 0xd670b7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
3:16:11 PM:  5: 0xf447c5  [node]
3:16:11 PM:  6: 0xf56cad v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
3:16:11 PM:  7: 0xf313ae v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
3:16:11 PM:  8: 0xf32777 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
3:16:11 PM:  9: 0xf1394a v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
3:16:11 PM: 10: 0x12d8caf v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
3:16:11 PM: 11: 0x1705b39  [node]
3:16:12 PM: Aborted (core dumped)
3:16:12 PM: ​
3:16:12 PM: "build.command" failed                                        
3:16:12 PM: ────────────────────────────────────────────────────────────────
3:16:12 PM: ​
3:16:12 PM:   Error message
3:16:12 PM:   Command failed with exit code 134: npm run docs:build (https://ntl.fyi/exit-code-134)
3:16:12 PM: ​
3:16:12 PM:   Error location
3:16:12 PM:   In Build command from Netlify app:
3:16:12 PM:   npm run docs:build
3:16:12 PM: ​
3:16:12 PM:   Resolved config
3:16:12 PM:   build:
3:16:12 PM:     command: npm run docs:build
3:16:12 PM:     commandOrigin: ui
3:16:12 PM:     environment:
3:16:12 PM:       - Production
3:16:12 PM:     publish: /opt/build/repo/dist
3:16:12 PM:     publishOrigin: ui
3:16:12 PM:   plugins:
3:16:12 PM:     - inputs: {}
3:16:12 PM:       origin: ui
3:16:12 PM:       package: "@netlify/plugin-lighthouse"
3:16:13 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
3:16:13 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:16:13 PM: Failing build: Failed to build site
3:16:13 PM: Finished processing build request in 1m28.385s

How should I handle it?

@ivankf check out the β€œAdjust how Node.js runs” section of the article linked above:

Adjusting the --max-old-space-size is the typical solution for this error.