问题
I am getting the following error when I try to run the command
ng update @angular/cli @angular/core --allow-dirty
Repository is not clean. Update changes will be mixed with pre-existing changes.
Using package manager: 'npm'
Collecting installed dependencies...
Found 28 dependencies.
Package '@angular/cli' is not a dependency.
回答1:
First commit all your changes to the repo and then try following commands.
npm i -g @angular/cli@8.0.0
and
ng update --all --force
Please read this issue on github
回答2:
In my case it was missing node_modules
folder. Make sure to run npm i
before updating.
回答3:
I ran into this same issue/error message because I had switched branches that were drastically different and not yet run npm install
on the branch to get the current version installed which at this point was Angular 7. After that completed, I ran the following again to install the latest version; Angular 8:
ng update @angular/cli @angular/core
This time the error did not appear and the upgrade was a success. It appears that the upgrade process is looking for valid files to know what version it's updating from, and if there is a missing or empty node_modules
folder, Angular can't tell what exactly is being updated and will throw this error. It makes sense because the CLI behaves differently based on the old version being upgraded and how many versions are being updated, so if it has nothing to read from for upgrading it can't continue.
来源:https://stackoverflow.com/questions/57751607/package-angular-cli-is-not-a-dependency