NPM install killed without a reason [Fixed]

#StandWithUkraine
Today, 25th June 2022, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putinโ€™s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

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.

โš ๏ธ Though this solution works for mentioned issue, by doing this, you might create a lot of different much worsen issues: in case if some other process will consume whole RAM, other processes will start consuming very slow swap pseude-memory. And in the end your system might become very slow. So we never recommend using swap. Instead you can try replace npm with yarn

NPM install killed

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

Best related