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

Node Error:

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xafcff0 node::Abort() [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 2: 0xa14113 node::FatalError(char const*, char const*) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 3: 0xce5c7e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 4: 0xce5ff7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 5: 0xeb4495  [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 6: 0xec3c11 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 7: 0xec67be v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 8: 0xe881ea v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
 9: 0x11fd286 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
10: 0x15e67d9  [/home/ubuntu/.nvm/versions/node/v16.9.1/bin/node]
Aborted (core dumped)
error Command failed with exit code 134.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

When you compile the node app then it creates Heap Memory to compile code. Heap memory size is limited by default so if your app size is large then need to add more memory. 

To increase the size of Heap Memory run one of the following commands as your requirement.

# For 2 GB
export NODE_OPTIONS="--max-old-space-size=2048"

# For 3 GB
export NODE_OPTIONS="--max-old-space-size=3072"

# For 4 GB
export NODE_OPTIONS="--max-old-space-size=4096"

# For 5 GB
export NODE_OPTIONS="--max-old-space-size=5120"

# For 6 GB
export NODE_OPTIONS="--max-old-space-size=6144"

# For 7 GB
export NODE_OPTIONS="--max-old-space-size=7168"

# For 8 GB
export NODE_OPTIONS="--max-old-space-size=8192"


Keywords: