Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  Web Hosting FAQ  >  Prevent NPM Install from Being Killed by Checking the Swap File
Top Scroll

Prevent NPM Install from Being Killed by Checking the Swap File

 2 min

Sometimes you are unable to perform npm install. You might face issues like command getting freezed, and after few minutes, npm displays ‘Killed’ message and breaks.

You can try several ways to resolve this issue as below:

  1. Install npm with every single dependency in package.json (about 20 dependencies, mostly grunt related).
  2. In package.json, remove ^ and ~ character to ensure npm only fetches correct version of dependencies (don’t compare and get latest version).
  3. Note that bower installation can go normal with about ~10 dependencies of AngularJS.

Try to npm rm -rf node_modules && npm cache clean, then npm install again does not work too, npm still be killed.

Steps to Prevent npm Install From Being Killed

This issue occurs mainly due to dirty workspace of node modules and for that you just need to clean the cache. But still for many the problem still persists. Many face the issue that the command runs on the local machine without any problem and the remote machine comprises of the same environment too. The difference is only about the machine configuration.

Check the example of configuration:

  • Local Machine Configuration: Dual core 1.3Ghz, with 4GB RAM and 4GB swap file, 256GB SSD.
  • Remote Machine Configuration: Single core CPU, with 512MB RAM and 20GB SSD
  • Even with this configuration you get an error npm install was Killed, after laggy (|) rotation

So, you can see that the biggest difference is memory. Here the remote machine (which is running Apache, nginx and MySQL) doesn’t have enough memory for npm to build something during the installation of dependencies – many dependencies need to be rebuilt by make.

For this check your swap file in remote machine using the below command:

sudo swapon -s

You will get the result as no swap file are available:

Filename                Type        Size    Used    Priority

Then create a 1GB swap file (on SSD system, swap speed can be much faster)

sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024k

Prepare the swap file using the below command:

sudo mkswap /swapfile

And activate it by executing this command:

sudo swapon /swapfile

Continue swap file after reboot by copying configuration on to the below path:

sudo nano /etc/fstab
/swapfile none swap sw 0 0

To make swap file to be a buffer for securing the application crashes, use the below command:

echo 10 | sudo tee /proc/sys/vm/swappiness echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Lastly, set correct permission on it:

sudo chown root:root /swapfile sudo chmod 0600 /swapfile

Then, clean cache and rebuild with npm:

npm cache clean npm install

That’s it! Install script is successfully completed. It takes just about 5 minutes for npm and make to build and install required dependencies. Then just npm start and your dashboard is online!

Conclusion

If you already succeed in something and fail with the same tasks, make sure to check what is different along with the software and hardware to detect the reason of failure.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.