在使用Angular 7 CLI并尝试创建新的Angular App时,出现以下错误:
/ bin / sh:cnpm:找不到命令
2018-11-04 13:27:17 ⌚ COMPUTER_X in ~/TEK/learn
○ → ng new firebase-auth
? Would you like to add Angular routing? No
? Which stylesheet format would you like to use? CSS
CREATE firebase-auth/README.md (1029 bytes)
....
CREATE firebase-auth/e2e/src/app.po.ts (208 bytes)
/bin/sh: cnpm: command not found
Package install failed, see above.
2018-11-04 13:27:25 ⌚ COMPUTER_X in ~/TEK/learn
○ →
我正在Mac上通过以下设置运行它:
2018-11-04 13:22:57 ⌚ COMPUTER_X in ~/TEK/learn
○ → npm --version
6.4.1
2018-11-04 13:23:01 ⌚ COMPUTER_X in ~/TEK/learn
○ → ng --version
Angular CLI: 7.0.3
Node: 8.12.0
OS: darwin x64
Angular:
...
Package Version
------------------------------------------------------
@angular-devkit/architect 0.10.3
@angular-devkit/core 7.0.3
@angular-devkit/schematics 7.0.3
@schematics/angular 7.0.3
@schematics/update 0.10.3
rxjs 6.3.3
typescript 3.1.3
2018-11-04 13:23:04 ⌚ COMPUTER_X in ~/TEK/learn
○ → node --version
v8.12.0
2018-11-04 13:23:25 ⌚ COMPUTER_X in ~/TEK/learn
○ →
此错误的原因是什么?有人遇到过吗?
答案 0 :(得分:1)
这很有趣。
首先,您可以看到Angular
的配置:
localhost:ng-test near$ ng config -g
We found a global configuration that was used in Angular CLI 1. It has been
automatically migrated.
{
"version": 1,
"cli": {
"packageManager": "cnpm"
},
"newProjectRoot": "./",
"schematics": {},
"architect": {},
"targets": {},
"projects": {}
}
您可以看到您的cli.packageManager
是cnpm
。
因此,有两种方法可以解决此问题。
1。全局安装cnpm
npm install -g cnpm
2。更改cli.packageManager
ng config -g cli.packageManager npm
之后,您可以再次检查配置。
localhost:ng-test near$ ng config -g
We found a global configuration that was used in Angular CLI 1. It has been
automatically migrated.
{
"version": 1,
"cli": {
"packageManager": "npm"
},
"newProjectRoot": "./",
"schematics": {},
"architect": {},
"targets": {},
"projects": {}
}