Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FATAL ERROR: JavaScript heap out of memory when using any "npm" command

I'm getting error (FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory) when try to run any npm command. Error occurs even by running "npm -v".

have also gone through the thread-(npm install - javascript heap out of memory ) but this didn't helped me out in my case.

Fetal error

    FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed 
    - 
    JavaScript heap out of memory
    1: 000000013F56F04A 
       v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
    2: 000000013F54A0C6 node::MakeCallback+4518
    3: 000000013F54AA30 node_module_register+2032
    4: 000000013F7D20EE v8::internal::FatalProcessOutOfMemory+846
    5: 000000013F7D201F v8::internal::FatalProcessOutOfMemory+639


    6: 000000013FCF2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556

     7: 000000013FCE9C46 v8::internal::ScavengeJob::operator=+24310
     8: 000000013FCE829C v8::internal::ScavengeJob::operator=+17740
     9: 000000013FCEE1B7 v8::internal::Heap::CreateFillerObjectAt+1175
    10: 000000013FB7C5B3 
    v8::internal::interpreter::Interpreter::GetDispatchCounters
    Object+78451
    11: 000000013F4D1132 
        v8::internal::StackGuard::ArchiveSpacePerThread+52082
    12: 000000013F4D17F3 
        v8::internal::StackGuard::ArchiveSpacePerThread+53811
    13: 000000013F5B1474 uv_dlerror+2436
    14: 000000013F5B21D8 uv_run+232

15: 000000013F55128E node::NewContext+1390
16: 000000013F55189B node::NewIsolate+603
17: 000000013F551D07 node::Start+839
18: 000000013F40935C node::MultiIsolatePlatform::MultiIsolatePlatform+604
19: 000000013FFAA93C 
   v8::internal::compiler::OperationTyper::ToBoolean+134796
20: 0000000076D3555D BaseThreadInitThunk+13
21: 0000000076F9385D RtlUserThreadStart+29

<--- Last few GCs --->

[13304:0000000000182610]   135335 ms: Mark-sweep 1396.6 (1426.7) -> 1396.6 (1424
.7) MB, 2368.0 / 0.0 ms  (+ 0.0 ms in 1 steps since start of marking, biggest st
ep 0.0 ms, walltime since start of marking 2368 ms) (average mu = 0.099, current
 mu = 0.035) fi[13304:0000000000182610]   135404 ms: Scavenge 1397.6 (1424.7) ->
 1397.1 (1428.2) MB, 3.7 / 0.0 ms  (average mu = 0.099, current mu = 0.035) allo
cation failure


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - 
JavaS
cript heap out of memory
 1: 000000013FD7F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
 2: 000000013FD5A0C6 node::MakeCallback+4518
 3: 000000013FD5AA30 node_module_register+2032
 4: 000000013FFE20EE v8::internal::FatalProcessOutOfMemory+846
 5: 000000013FFE201F v8::internal::FatalProcessOutOfMemory+639
 6: 0000000140502BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
 7: 00000001404F9C46 v8::internal::ScavengeJob::operator=+24310
 8: 00000001404F829C v8::internal::ScavengeJob::operator=+17740
 9: 00000001404FE1B7 v8::internal::Heap::CreateFillerObjectAt+1175
10: 000000014038C5B3 
    v8::internal::interpreter::Interpreter::GetDispatchCounters
    Object+78451
11: 000000013FCE1132 v8::internal::StackGuard::ArchiveSpacePerThread+52082
12: 000000013FCE17F3 v8::internal::StackGuard::ArchiveSpacePerThread+53811
13: 000000013FDC1474 uv_dlerror+2436
14: 000000013FDC21D8 uv_run+232
15: 000000013FD6128E node::NewContext+1390
16: 000000013FD6189B node::NewIsolate+603
17: 000000013FD61D07 node::Start+839
18: 000000013FC1935C node::MultiIsolatePlatform::MultiIsolatePlatform+604
19: 00000001407BA93C 
   v8::internal::compiler::OperationTyper::ToBoolean+134796
20: 0000000076D3555D BaseThreadInitThunk+13
21: 0000000076F9385D RtlUserThreadStart+29
like image 595
Ayush Jain Avatar asked May 06 '19 06:05

Ayush Jain


People also ask

How do I stop JavaScript heap out of memory?

Open the Start menu, search for Advanced System Settings, and select the Best match. In the Variable name field enter NODE_OPTIONS. In the Variable value field enter --max-old-space-size=4096. This value will allocate 4GB of virtual memory to Node.

How do I fix heap memory error?

How to fix it: In some cases, to mitigate the problem, it is enough to increase the maximum heap size by adding the -Xmx to your JVM application startup settings and setting it to a larger value.

How do I fix a process out of memory exception in Node JS?

This exception can be solved by increasing the default memory allocated to our program to the required memory by using the following command. Parameters: SPACE_REQD: Pass the increased memory space (in Megabytes).

How much memory does npm install need?

Please reserve at least 6 GB for OS resources and npm On-Site appliance containers. Once installed, you can configure where registry data is stored on your server via the "Storage" paths on the "Settings" page of the admin web console (port 8800).


2 Answers

You need to raise the amount of memory allowed for node.

You can do that in a global scope by:

  1. Open a cmd window
  2. Run setx NODE_OPTIONS --max_old_space_size=10240
  3. Close all cmd/code editors
  4. Reopen cmd and run your node command again (npm, etc.)
like image 91
Sat Thiru Avatar answered Oct 06 '22 14:10

Sat Thiru


I had exactly the same issue and it took ages to find out what was happening. If even npm -v fails on you then your problem is not caused by memory shortage but incorrect settings in .npmrc file. In my case I copied .npmrc from my old machine and I had prefix and cache settings redefined like that:

prefix=D:\npm-projects\npm
cache=D:\npm-projects\npm-cache

On my new machine I have only C:\ drive thus npm was going crazy trying to process these settings. As soon as I changed everything to point to C:\npm-projects\xxxx problem went away.

like image 30
alexeygt Avatar answered Oct 06 '22 15:10

alexeygt