'NPM not installing packages

I have a project with dependencies in package.json. When I install with npm install, I get packages installed in ~/.npm but not in the current folder's node_modules.

NPM is creating node_modules, but not installing packages there. There's a .staging folder within node_modules, which contains all of the packages for the projects, but they're not being moved out after retrieval.

Using Node v6.9.1 / npm v3.10.8.

There aren't any other projects/node_modules installed in directories higher than the current one, though there is a package.json in the parent directory as well. No node_modules directory gets created in the parent directory, however.

Strangely enough, when I manually install a package like npm install @angular/core it installs without problem.

This is on Ubuntu 16.04.

package.json:

{ 
  "name": "", 
  "version": "0.5.0", 
  "description": "website (Angular2/NodeJS)", 
  "main": "main.js", 
  "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
  }, 
  "author": "John Halbert <https://halbert.tech> ([email protected])", 
  "license": "SEE LICENSE IN LICENSE.md", 
  "dependencies": { 
    "@angular/common": "^2.1.1", 
    "@angular/compiler": "^2.1.1", 
    "@angular/core": "^2.1.1", 
    "@angular/forms": "^2.1.1", 
    "@angular/http": "^2.1.1", 
    "@angular/platform-browser": "^2.1.1", 
    "@angular/platform-browser-dynamic": "^2.1.1", 
    "@angular/router": "^3.1.1", 
    "core-js": "^2.4.1", 
    "reflect-metadata": "^0.1.8", 
    "systemjs": "^0.19.39", 
    "zone.js": "^0.6.26" 
  },
  "devDependencies": { 
    "concurrently": "^3.1.0", 
    "typings": "^1.4.0" 
  } 
}


Solution 1:[1]

Try to run

echo "" > $(npm config get userconfig)
npm config edit

To see if you have change de node modules default folder, if so, you can reset the configurations by doing

echo "" > $(npm config get globalconfig)
npm config --global edit

Solution 2:[2]

After doing more research it looks like this is a memory issue with my server. Running on a low-end VPS with 128Mb RAM.

There are a few suggestions on how to deal with this. I found others suggesting npm config set jobs 1 as a way to limit memory usage, but this hasn't worked for me. Others suggest adding (more) swap, which is disallowed by my hosting provider.

The npm process is actually being killed so it appears this is likely the culprit.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ricardo Machado
Solution 2 John Halbert