nuxt: JavaScript heap out of memory in Dev env, several times a day

Version

v2.5.1

Reproduction link

http://not-a-real-link.com

Steps to reproduce

After programming some hours in dev env, node server crashs with this error :

<--- Last few GCs --->

[47073:0x104800000]  7043097 ms: Mark-sweep 1380.1 (1424.3) -> 1380.0 (1424.8) MB, 1170.5 / 0.0 ms  (average mu = 0.159, current mu = 0.001) allocation failure scavenge might not succeed
[47073:0x104800000]  7044402 ms: Mark-sweep 1380.7 (1424.8) -> 1380.6 (1425.3) MB, 1301.5 / 0.0 ms  (average mu = 0.080, current mu = 0.003) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0xa30765cfb7d]
Security context: 0x0da72a89d8c1 <JSObject>
    1: parsePath(aka parsePath) [0xda7b3e73391] [/Users/pro/Documents/CLIENTS/node_modules/vue/dist/vue.runtime.common.dev.js:~497] [pc=0xa30788a252d](this=0x0da7414025b1 <undefined>,0x0da7391ee3c1 <String[10]: inputValue>)
    2: initWatch(aka initWatch) [0xda7b3e75921] [/Users/pro/Documents/CLIENTS/node_mo...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x100061233 node::Abort() [/usr/local/bin/node]
 2: 0x10006184d node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x100167953 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x1001678f4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x1004288e8 v8::internal::Heap::UpdateSurvivalStatistics(int) [/usr/local/bin/node]
 6: 0x10042a305 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
 7: 0x100427c7d v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x100426a73 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x10042e941 v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10042e990 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x10040ed57 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
12: 0x1005ec896 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0xa30765cfb7d 
14: 0xa30788a252d 
Abort trap: 6

I’m not able give any reproduce repo due to the confidentiality of my project.

I’m using nuxt-apollo in this project, not sure if it can related with this memory leaks.

What is expected ?

Having a server running correctly

What is actually happening?

Server crash several (≈ 2-6) times a day

Additional comments?

Thanks for your help !

<div align="right">This bug report is available on Nuxt community (#c8943)</div>

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 23
  • Comments: 43 (4 by maintainers)

Most upvoted comments

For everyone who faces this problem. Try to bump memory limit with max-old-space-size node optimization flag, but use it correctly. As example:

"scripts": {
  "dev": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js",
  "build": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js build",
  "start": "node --max-old-space-size=4096 node_modules/nuxt/bin/nuxt.js start"
}

And example for TS guys:

"scripts": {
  "dev": "node --max-old-space-size=4096 node_modules/@nuxt/typescript-runtime/bin/nuxt-ts.js",
  "build": "node --max-old-space-size=4096 node_modules/@nuxt/typescript-runtime/bin/nuxt-ts.js build",
  "start": "node --max-old-space-size=4096 node_modules/@nuxt/typescript-runtime/bin/nuxt-ts.js start"
}

If you still get errors, allocate some more memory --max-old-space-size=8192 etc. If you don’t have enough memory on the node, try to add flag --optimize_for_size, this will allow less memory to be allocated, but may affect performance and give some errors in theory.

Can confirm this is still happening in Nuxt 2.14.0

this is still happening to me. I am running npm run dev and if i try to load localhost:3000 it either never loads or crashes the server.

+1

@clarkdo I’m now on Nuxt 2.6.1 and I still have memory leaks 😕 Today, it happened a couple of time with this error:

<--- Last few GCs --->

[35454:0x104800000]  3763735 ms: Mark-sweep 1381.6 (1425.6) -> 1381.5 (1426.6) MB, 1147.4 / 0.0 ms  (average mu = 0.063, current mu = 0.001) allocation failure scavenge might not succeed
[35454:0x104800000]  3764482 ms: Mark-sweep 1382.2 (1426.6) -> 1382.1 (1426.6) MB, 744.6 / 0.0 ms  (average mu = 0.039, current mu = 0.003) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x104b4da4fb7d]
Security context: 0x0041f2a9d8c1 <JSObject>
    1: new Set(aka Set) [0x41f2a90331](this=0x00411e702691 <the_hole>)
    2: ConstructFrame [pc: 0x104b4da09e66]
    3: initWatch(aka initWatch) [0x41c0935691] [/Users/pro/Documents/CLIENTS/node_modules/vue/dist/vue.runtime.common.dev.js:~4857] [pc=0x104b50408d31](this=0x00411e7025b1 <undefined>,0x0041b38fc9e1 <VueComponent map = 0...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x100061233 node::Abort() [/usr/local/bin/node]
 2: 0x10006184d node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x100167953 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x1001678f4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x1004288e8 v8::internal::Heap::UpdateSurvivalStatistics(int) [/usr/local/bin/node]
 6: 0x10042a305 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
 7: 0x100427c7d v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x100426a73 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x10042e941 v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10042e990 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x10040ed57 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
12: 0x1005ec896 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0x104b4da4fb7d 
Abort trap: 6

Thanks again for you help

i’m still having memory leak in 3.6.3

After a few hours of trying to find the issue, I’ve found the fix for me.

If you are using the "@nuxtjs/auth-next" and "@nuxtjs/axios" module with proxy enabled in axios. Try setting the baseUrl option in axios to "/", this fixed the issue for me.

even tho the nuxt axios docs says: “WARNING: baseURL and proxy cannot be used at the same time, so when the proxy option is in use, you need to define prefix instead of baseURL.”

There is a problem with an infinite loop or something.

Hello! I have similar problem. node v14.18.2 “nuxt”: “2.16.3”

<— Last few GCs —>

[2620:00000271AC58CC40] 422814 ms: Scavenge 1935.3 (2028.1) -> 1923.9 (2028.1) MB, 21.6 / 0.0 ms (average mu = 0.727, current mu = 0.560) allocation failure [2620:00000271AC58CC40] 423588 ms: Scavenge 1935.7 (2028.1) -> 1925.7 (2028.1) MB, 35.5 / 0.0 ms (average mu = 0.727, current mu = 0.560) task [2620:00000271AC58CC40] 424582 ms: Scavenge 1954.8 (2053.4) -> 1951.1 (2053.4) MB, 16.1 / 0.0 ms (average mu = 0.727, current mu = 0.560) allocation failure

<— JS stacktrace —>

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 00007FF682C8428F napi_wrap+133311 2: 00007FF682C1DE66 SSL_get_quiet_shutdown+63062 3: 00007FF682C1ECFD node::OnFatalError+301 4: 00007FF683501B2E v8::Isolate::ReportExternalAllocationLimitReached+94 5: 00007FF6834E691D v8::SharedArrayBuffer::Externalize+781 6: 00007FF68339012C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516 7: 00007FF68337ABAB v8::internal::NativeContextInferrer::Infer+59739 8: 00007FF68335FE7F v8::internal::MarkingWorklists::SwitchToContextSlow+56975 9: 00007FF683373B6B v8::internal::NativeContextInferrer::Infer+31003 10: 00007FF68336AC4D v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6285 11: 00007FF683372DBE v8::internal::NativeContextInferrer::Infer+27502 12: 00007FF683376E0B v8::internal::NativeContextInferrer::Infer+43963 13: 00007FF683380802 v8::internal::ItemParallelJob::Task::RunInternal+18 14: 00007FF683380791 v8::internal::ItemParallelJob::Run+641 15: 00007FF683353DF3 v8::internal::MarkingWorklists::SwitchToContextSlow+7683 24: 00007FF6833A5705 v8::internal::Factory::AllocateRaw+37 25: 00007FF6833B9D7F v8::internal::FactoryBasev8::internal::Factory::NewRawTwoByteString+79 26: 00007FF6833B4135 v8::internal::Factory::NewStringFromUtf8+181 27: 00007FF6834FD7FF v8::String::NewFromUtf8+287 28: 00007FF682B39B31 v8::internal::WasmTableObject::WasmTableObject+33409 29: 00007FF682C3968B v8::internal::Malloced::operator delete+4107 30: 00007FF683523FAC v8::internal::SetupIsolateDelegate::SetupHeap+44252 31: 000000539E73595B error Command failed with exit code 134.

Still got this problem… Looks something plays in infinite loop but I don’t know what it is.

An alternative to modifying the script commands: NODE_OPTIONS=--max_old_space_size=4096 npm run build In my case this was only a build issue that i needed to do on a one off

Thank you @clarkdo for your fix ! Unfortunately I still have memory leaks troubles 😕

My server crashed again today with this error:

<--- Last few GCs --->

[57880:0x104800000] 18415949 ms: Mark-sweep 1383.0 (1433.0) -> 1375.2 (1433.0) MB, 813.2 / 0.0 ms  (average mu = 0.092, current mu = 0.012) allocation failure scavenge might not succeed
[57880:0x104800000] 18416785 ms: Mark-sweep 1383.1 (1433.0) -> 1376.8 (1433.0) MB, 822.2 / 0.0 ms  (average mu = 0.055, current mu = 0.016) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x12435151d8c1 <JSObject>
    0: builtin exit frame: clear(this=0x12438d37fe39 <Set map = 0x124357783d81>,0x12438d37fe39 <Set map = 0x124357783d81>)

    1: initWatch(aka initWatch) [0x1243e28ad601] [/Users/pro/Documents/CLIENTS/Hubworkair/hubworkair.com/node_modules/vue/dist/vue.runtime.common.dev.js:~4857] [pc=0x30ee0619073c](this=0x1243f59025b1 <undefined>,0x1243dd6d6589 <VueComponent map = 0x1243853105d1>,0x1243df379...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x100061233 node::Abort() [/usr/local/bin/node]
 2: 0x10006184d node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x100167953 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x1001678f4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x1004288e8 v8::internal::Heap::UpdateSurvivalStatistics(int) [/usr/local/bin/node]
 6: 0x10042a305 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
 7: 0x100427c7d v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x100426a73 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x10042e941 v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10042e990 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x10040e733 v8::internal::Factory::AllocateRawArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
12: 0x10040e5e9 v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::Heap::RootListIndex, int, v8::internal::Object*, v8::internal::PretenureFlag) [/usr/local/bin/node]
13: 0x100539f89 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet, 1>::Allocate(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [/usr/local/bin/node]
14: 0x10053a37c v8::internal::OrderedHashTable<v8::internal::OrderedHashSet, 1>::Clear(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashSet>) [/usr/local/bin/node]
15: 0x1005189ea v8::internal::JSSet::Clear(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSSet>) [/usr/local/bin/node]
16: 0x1001d61b0 v8::internal::Builtin_Impl_SetPrototypeClear(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
17: 0x30ee023cfcdd 
18: 0x30ee0619073c 
19: 0x30ee0238e458 
Abort trap: 6

Thanks for help

Fresh install here, runs for like 10 minutes and the crashes over and over again with the same memory issue.

@ajahongir i traced it to tailwind css module https://github.com/nuxt-modules/tailwindcss/issues/745#issuecomment-1817920731 not using nuxt anymore it’s better to be safe than sorry

In my case everything works fine, the build and dev process, but when I build the project and it creates the dist folder, and then run npm run dev, the project shows the out of memory error.

So you need to delete all files created by nuxt, install again and run npm run dev

But I dont know why

I solved the problem like this. LINK // nginx config

root /var/www/NUXT_PROJECT_PATH/dist;

    location ~* \.(?:ico|gif|jpe?g|png|woff2?|eot|otf|ttf|svg|js|css)$ {
        expires $expires;
        add_header Pragma public;
        add_header Cache-Control "public";

        try_files $uri $uri/ @proxy;
    }