npm install gets killed
The following happended on a DigitalOcean 512 MB VPS running Ubuntu 14.04.3
.
My package.json
looks pretty non-hardcore to me.
{
"private": true,
"devDependencies": {
"gulp": "^3.8.8",
"stringify": "^3.2.0"
},
"dependencies": {
"angular": "^1.4.8",
"angular-payments": "^1.0.7",
"angular-resource": "^1.4.8",
"angular-route": "^1.4.8",
"angular-sanitize": "^1.4.8",
"angular-ui-bootstrap": "^1.0.3",
"bootstrap-sass": "^3.0.0",
"jquery": "^2.2.0",
"jquery-ui": "^1.10.5",
"jquery.viewport": "^0.1.0",
"laravel-elixir": "^4.0.0",
"ng-file-upload": "^11.1.1"
}
}
Issue
Running npm install --verbose
ends with
npm verb about to build /home/username/html/node_modules/laravel-elixir/node_modules/partialify
npm info build /home/username/html/node_modules/laravel-elixir/node_modules/partialify
npm verb afterAdd /home/username/.npm/is-glob/2.0.1/package/package.json not in flight; writing
npm verb afterAdd /home/username/.npm/normalize-path/2.0.1/package/package.json not in flight; writing
npm verb readDependencies loading dependencies from /home/username/html/node_modules/laravel-elixir/node_modules/gulp-uglify/node_modules/uglify-js/package.json
npm verb write writing to /home/username/html/node_modules/laravel-elixir/node_modules/gulp-babel/node_modules/through2/node_modules/readable-stream/package.json
Killed
getting Killed
at random steps.
Cause
Looking into kern.log
gives this:
Jan 23 19:05:18 server1 kernel: [135502.129029] Out of memory: Kill process 16877 (npm) score 627 or sacrifice child
Jan 23 19:05:18 server1 kernel: [135502.129095] Killed process 16877 (npm) total-vm:1484264kB, anon-rss:313692kB, file-rss:0kB
So its running out of memory, I didn’t know npm was this memory hungry.
Solution
Now we have to either increase server’s memory and/or add swap.
Adding a 1GB
swap file.
Full Details: DigitalOcean Post
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
and it worked. I upgraded the server as well, more ram is always better ;)