npm install doesn't work in Windows PowerShell

node.js, npm, powershell

Solution

Use `.npmrc` to set the prefix explicitly:

Go to `\Users\%USERNAME%\.npmrc`. For example, in Powershell:

Notepad "\Users\$env:USERNAME\.npmrc"

Set the prefix:

prefix = "C:/Program Files/nodejs" 

References

- Is there a manual install of node.js for Windows 7?

- Opening a program with PowerShell from a shortcut

- nodeJS Modules: Loading from the Global Folders

- npm config Readme

- npm Folders: prefix configuration

- nodejs source: legacy-npm-self-install.js

- forward slash usage

Problem

So my problem is this. I have a project with a package.json. When I in the command prompt (cmd.exe) run "npm install" everything installs as expected. However when I do the exact same thing in PowerShell (powershell.exe) I get an error: "npm ERR! Error: ENOENT, open 'c:\package.json'" even though I ran "npm install" in the path of the project. It always searches for package.json in c: for some reason I can't understand. Below is the npm-debug.log (which also is written i c: even though my path is c:\code\myProject): ``` 0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe', 1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 1 verbose cli 'install' ] 2 info using npm@1.3.11 3 info using node@v0.10.21 4 verbose node symlink C:\Program Files\nodejs\\node.exe 5 error install Couldn't read dependencies 6 error Error: ENOENT, open 'c:\package.json' 7 error If you need help, you may report this log at: 7 error <http://github.com/isaacs/npm/issues> 7 error or email it to: 7 error <npm-@googlegroups.com> 8 error System Windows_NT 6.2.9200 9 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" 10 error cwd c:\ 11 error node -v v0.10.21 12 error npm -v 1.3.11 13 error path c:\package.json 14 error code ENOENT 15 error errno 34 16 verbose exit [ 34, true ] ``` I can't find a solution to this problem anywhere. The PATH variable is setup correctly since both node and npm itself works.

Original source