Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript heap out of memory when building Vue.js app

Tags:

vue.js

vue-cli

I'm trying to build a vue.js app for production. This error message always appears midway through.

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I already tried to increase the memory by adding --max_old_space_size=4096 and even tried to change it to 8192, but to no avail. I am using a Mac with 8 GB of RAM so I'm not sure why this is happening.

This is the code I run for npm run build:

vue-cli-service build --max_old_space_size=4096
like image 272
Jaye Hernandez Avatar asked Apr 25 '19 06:04

Jaye Hernandez


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 will you solve common causes of memory leaks in VUE JS applications?

Resolving the Memory Leak In the above example, we can use our hide() method to do some clean up and solve the memory leak prior to removing the select from the DOM. To accomplish this, we will keep a property in our Vue instance's data object and we will use the Choices API's destroy() method to perform the clean up.

Why JavaScript Heap out of memory occurs?

This generally occurs on larger projects where the default amount of memory allocated by Node (1.5gb) is insufficient to complete the command successfully.

How do I check my Vue memory leaks?

js Memory Leak Example. To see the memory leak occur, open the Chrome Task Manager and then click the hide/show button 50 or so times. You should notice the memory continue to increase and not be reclaimed.


1 Answers

I ran into this problem too. The memory limitation was with Node so running this command worked:

NODE_OPTIONS=--max_old_space_size=4096 npm run build

On Windows, use:

set NODE_OPTIONS=--max_old_space_size=4096 
npm run build

The default memory limit for Node is 512MB, running this command temporarily increased it to 4GB.

like image 186
BaronGrivet Avatar answered Sep 22 '22 12:09

BaronGrivet