18

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.

dotnetdummy
  • 183
  • 1
  • 1
  • 6
  • I don't know node.js, but if it searches packages based on source path, the double \\ before node.exe may be the issue. HTH – Mat M Oct 24 '13 at 19:30

2 Answers2

25

For me, it was much easier to do this in Powershell.

$env:Path += ";C:\Program Files\nodejs\"

Ran "npm" in powershell, and came up straight away.

HelpfulStranger
  • 251
  • 3
  • 2
  • 3
    This won't set it permanently. A new shell won't have the environment path linked to node – Al V Feb 17 '17 at 19:50
  • 1
    THANK YOU. Literally this was driving me crazy. Don't know why the guides for node/npm aren't better about updating the path so you can use it in Powershell. – flareartist Aug 21 '18 at 20:48
14

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

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265