Angular 7 CLI:无法创建新应用程序,因为它会抛出错误

Angular 7 CLI: Unable to create a new app as it throws error

当使用 Angular 7 CLI 并尝试创建新的 Angular 应用程序时,出现以下错误:

/bin/sh: cnpm: command not found

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
○ →

这个错误的原因是什么?有人遇到过吗?

这是一件有趣的事情。 首先可以看到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.packageManagercnpm

所以有两种方法可以解决这个问题。

1.install cnpm 全球

npm install -g cnpm

2.change 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": {}
}