npm install - javascript heap out of memory

Solution 1:

You can launch NPM using :

node --max-old-space-size=8000 $(which npm) install -g ionic

As described here, the default is 4000 (4Gb).

Solution 2:

I flagged this as a duplicate, but in case anyone happens across it, I posted the modern solution to this problem over at https://stackoverflow.com/a/48895989/4200039:

As of v8.0 shipped August 2017, the NODE_OPTIONS environment variable exposes this configuration (see NODE_OPTIONS has landed in 8.x!). Per the article, only options whitelisted in the source are permitted, which includes "--max_old_space_size".

So I put in my .bashrc: export NODE_OPTIONS=--max_old_space_size=4096

Solution 3:

Try, node --max-old-space-size=<size> where size is in megabytes.