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.
⚠️ 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