{"id":17224,"date":"2024-05-22T13:30:03","date_gmt":"2024-05-22T13:30:03","guid":{"rendered":"https:\/\/hostvento.com\/kb\/web-hosting\/prevent-npm-install-from-being-killed-by-checking-the-swap-file\/"},"modified":"2024-06-17T07:50:43","modified_gmt":"2024-06-17T07:50:43","slug":"prevent-npm-install-from-being-killed-by-checking-the-swap-file","status":"publish","type":"docs","link":"https:\/\/www.hostvento.com\/kb\/docs\/hosting-faqs\/prevent-npm-install-from-being-killed-by-checking-the-swap-file\/","title":{"rendered":"Prevent NPM Install from Being Killed by Checking the Swap File"},"content":{"rendered":"\n<p>You may occasionally be unable to run npm install. You may experience problems such as commands freezing and npm displaying a &#8220;Killed&#8221; notice and breaking after a fewmile minutes..<\/p>\n\n\n\n<p>You can try several ways to resolve this issue as below:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install npm with every single dependency in package.json (about 20 dependencies, mostly grunt related).<\/li>\n\n\n\n<li>In package.json, remove ^ and ~ character to ensure npm only fetches correct version of dependencies (don\u2019t compare and get latest version).<\/li>\n\n\n\n<li>Note that bower installation can go normal with about ~10 dependencies of AngularJS.<\/li>\n<\/ol>\n\n\n\n<p>Try to&nbsp;<em>npm rm -rf node_modules &amp;&amp; npm cache clean<\/em>, then npm install again does not work too, npm still be killed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Prevent npm Install From Being Killed<\/h3>\n\n\n\n<p>The primary cause of this problem is unclean workspace from node modules; clearing the cache can resolve this. Yet, the issue still exists for a large number of people. Many encounter the difficulty that while the command executes flawlessly on the local machine, it also shares the same environment with the remote machine. There is only one machine configuration that differs.<\/p>\n\n\n\n<p><strong>Check the example of configuration:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Local Machine Configuration:<\/strong>&nbsp;Dual core 1.3Ghz, with 4GB RAM and 4GB swap file, 256GB SSD.<\/li>\n\n\n\n<li><strong>Remote Machine Configuration:<\/strong>&nbsp;Single core CPU, with 512MB RAM and 20GB SSD<\/li>\n\n\n\n<li>Even with this configuration you get an error&nbsp;<em>npm install<\/em>&nbsp;was Killed, after laggy (|) rotation<\/li>\n<\/ul>\n\n\n\n<p>So, you can see that the biggest difference is memory. Here the remote machine (which is running Apache, nginx and MySQL) doesn\u2019t have enough memory for npm to build something during the installation of dependencies \u2013 many dependencies need to be rebuilt by make.<\/p>\n\n\n\n<p>For this check your swap file in remote machine using the below command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo swapon -s<\/pre>\n\n\n\n<p>You will get the result as no swap file are available:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Filename&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Size&nbsp;&nbsp;&nbsp; Used&nbsp;&nbsp;&nbsp; Priority<\/pre>\n\n\n\n<p>Then create a 1GB swap file (on SSD system, swap speed can be much faster)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo dd if=\/dev\/zero of=\/swapfile bs=1024 count=1024k<\/pre>\n\n\n\n<p>Prepare the swap file using the below command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo mkswap \/swapfile<\/pre>\n\n\n\n<p>And activate it by executing this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo swapon \/swapfile<\/pre>\n\n\n\n<p>Continue swap file after reboot by copying configuration on to the below path:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/fstab<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\/swapfile none swap sw 0 0<\/pre>\n\n\n\n<p>To make swap file to be a buffer for securing the application crashes, use the below command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo 10 | sudo tee \/proc\/sys\/vm\/swappiness echo vm.swappiness = 10 | sudo tee -a \/etc\/sysctl.conf<\/pre>\n\n\n\n<p>Lastly, set correct permission on it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo chown root:root \/swapfile sudo chmod 0600 \/swapfile<\/pre>\n\n\n\n<p>Then, clean cache and rebuild with npm:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npm cache clean npm install<\/pre>\n\n\n\n<p>That\u2019s 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!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><a href=\"https:\/\/hostvento.com\/kb\/web-hosting\/learn-to-enable-litespeed-cache-for-wordpress\/\" target=\"_blank\" rel=\"noopener\"><strong>Learn to enable LiteSpeed Cache for WordPress<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may occasionally be unable to run npm install. You may experience problems such as commands freezing and npm displaying a &#8220;Killed&#8221; notice and breaking after a fewmile minutes.. You can try several ways to resolve this issue as below: Try to&nbsp;npm rm -rf node_modules &amp;&amp; npm cache clean, then npm install again does not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":23377,"menu_order":641,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-17224","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/17224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/comments?post=17224"}],"version-history":[{"count":2,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/17224\/revisions"}],"predecessor-version":[{"id":20478,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/17224\/revisions\/20478"}],"up":[{"embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/23377"}],"wp:attachment":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/media?parent=17224"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/doc_tag?post=17224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}