Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias is already in use by the "--collection" option and cannot be used by the "--change-detection" option

Tags:

alias

npm

angular

Environment:

  • Ubuntu 16.04
  • Angular CLI 1.7.3

I'm getting the error by executing ng generate component dashboard, but it also happens with 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.

I tried to look for an error in npm, ant I got the following error

$npm list
...
npm ERR! peer dep missing: @angular-devkit/[email protected], required by @schematics/[email protected]
npm ERR! peer dep missing: @angular-devkit/[email protected], required by @schematics/[email protected]

It looks something related with npm validate alias

function angular-cli.command.prototype.validateAlias (option, alias)

but I'm not sure why is taking "c" instead of "component".

like image 229
Joe Avatar asked Mar 14 '18 12:03

Joe


2 Answers

I don't know the root cause of this error, but this commit changed a lot of aliases (including "c" for "component")... If you change it locally in node_modules/@schematics/angular/component/schema.json to "cd", ng generate works again.

Note that when using ng g component test in a new project I don't reproduce this error. I'm using @nrwl/nx in the project that produces errors. The problem might lie in a version mismatch between ... I don't know what.

like image 69
David Palita Avatar answered Nov 10 '22 10:11

David Palita


I also dont know the cause of this error, but removing the explicitly installed @schematics/angular package solved it somehow:

npm uninstall @schematics/angular --save-dev
like image 45
Stefan Avatar answered Nov 10 '22 10:11

Stefan