npm install 在 Windows PowerShell 中不起作用 [英] npm install doesn't work in Windows PowerShell
问题描述
所以我的问题是这个.我有一个带有 package.json 的项目.当我在命令提示符 (cmd.exe) 中运行npm install"时,一切都会按预期安装.但是,当我在 PowerShell (powershell.exe) 中执行完全相同的操作时,我收到一个错误:npm ERR!错误:ENOENT,打开 'c:\package.json'" 即使我在路径中运行了npm install"该项目.它总是在 c: 中搜索 package.json 出于某种原因我无法理解.
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.
下面是 npm-debug.log(也写成 i c: 即使我的路径是 c:\code\myProject):
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 ]
我在任何地方都找不到解决此问题的方法.PATH 变量设置正确,因为 node 和 npm 本身都可以工作.
I can't find a solution to this problem anywhere. The PATH variable is setup correctly since both node and npm itself works.
推荐答案
使用 .npmrc
显式设置前缀:
Use .npmrc
to set the prefix explicitly:
转到
\Users\%USERNAME%\.npmrc
.例如,在 Powershell 中:
Go to
\Users\%USERNAME%\.npmrc
. For example, in Powershell:
Notepad "\Users\$env:USERNAME\.npmrc"
设置前缀:
Set the prefix:
prefix = "C:/Program Files/nodejs"
参考资料
- 是否可以手动安装适用于 Windows 7 的 node.js?
- 通过快捷方式使用 PowerShell 打开程序
- nodeJS 模块:从全局文件夹加载
- npm 配置自述
- npm 文件夹:前缀配置
- nodejs 源码: legacy-npm-self-install.js
- 正斜杠用法
这篇关于npm install 在 Windows PowerShell 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!