环境:
- Ubuntu 16.04
- Angular CLI 1.7.3
我在执行 ng generate component dashboard 时遇到错误,但在 ng generate c 时也会发生这种情况
$ ng generate component dashboard
The "c" alias is already in use by the "--collection" option
and cannot be used by the "--change-detection" option.
Please use a different alias.
我试图在 npm 中寻找错误,但我得到了以下错误
$npm list
...
npm ERR! peer dep missing: @angular-devkit/core@0.4.5, required by @schematics/angular@0.4.5
npm ERR! peer dep missing: @angular-devkit/schematics@0.4.5, required by @schematics/angular@0.4.5
它看起来与 npm validate alias 相关
function angular-cli.command.prototype.validateAlias (option, alias)
但我不确定为什么使用“c”而不是“component”。
最佳答案
我不知道这个错误的根本原因,但是这个 commit改变了很多别名(包括“组件”的“c”)......
如果您在 node_modules/@schematics/angular/component/schema.json
中将其本地更改为“cd”,ng generate
将再次运行。
请注意,在新项目中使用 ng g component test
时,我不会重现此错误。我在产生错误的项目中使用@nrwl/nx。问题可能在于版本不匹配......我不知道是什么。
关于angular - 别名已被 "--collection"选项使用,不能被 "--change-detection"选项使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49277567/