node.js npm install 在 Windows PowerShell 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19569990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm install doesn't work in Windows PowerShell
提问by dotnetdummy
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.
所以我的问题是这个。我有一个带有 package.json 的项目。当我在命令提示符 (cmd.exe) 中运行“npm install”时,一切都会按预期安装。但是,当我在 PowerShell (powershell.exe) 中执行完全相同的操作时,我收到一个错误:“npm ERR!错误:ENOENT,打开 'c:\package.json'”,即使我在该项目。它总是在 c: 中搜索 package.json 出于某种原因我无法理解。
Below is the npm-debug.log (which also is written i c: even though my path is c:\code\myProject):
下面是 npm-debug.log (也写成 ic: 即使我的路径是 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 [email protected]
3 info using [email protected]
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 <[email protected]>
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.
我在任何地方都找不到解决此问题的方法。PATH 变量设置正确,因为 node 和 npm 本身都可以工作。
采纳答案by Paul Sweatte
Use .npmrcto set the prefix explicitly:
用于.npmrc显式设置前缀:
Go to
\Users\%USERNAME%\.npmrc. For example, in Powershell:Notepad "\Users$env:USERNAME\.npmrc"Set the prefix:
prefix = "C:/Program Files/nodejs"
去
\Users\%USERNAME%\.npmrc。例如,在 Powershell 中:Notepad "\Users$env:USERNAME\.npmrc"设置前缀:
prefix = "C:/Program Files/nodejs"
References
参考
回答by HelpfulStranger
For me, it was much easier to do this in Powershell.
对我而言,在 Powershell 中执行此操作要容易得多。
$env:Path += ";C:\Program Files\nodejs\"
Ran "npm" in powershell, and came up straight away.
在powershell中运行“npm”,并立即出现。

