JavaScript heap out of memory when building Vue.js app

Jaye Hernandez picture Jaye Hernandez · Apr 25, 2019 · Viewed 7.5k times · Source

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

Answer

BaronGrivet picture BaronGrivet · Jul 25, 2019

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

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