NPM install killed without a reason [Fixed]

In most cases, any npm Killed message means that there is not enough RAM on the machine where you execute it.

For example, for me, it triggered when I executed npm run build on the machine with only 1GB RAM. But in same time, it worked fine on a machine with 2GB RAM.

To fix the issue without buying a new server (if you are running dev env, why do you need an expensive server?) we can create a swap file on the machine:

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf

This was tested on Ubuntu 14, 16, 18. The file will be persisted after reboot as well.

NPM install killed

#npm #ram #swap
Ivan Borshchov profile picture
Jan 23, 2021
by Ivan Borshchov
Did it help you?
Yes !

Best related