Package '@angular/cli' is not a dependency

AngularAngular Cli

Angular Problem Overview


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.

Angular Solutions


Solution 1 - Angular

In my case it was missing node_modules folder. Make sure to run npm i before updating.

Solution 2 - Angular

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

Solution 3 - Angular

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.

Solution 4 - Angular

Assuming you are upgrating from Angular 8.0 to Angular 9.0 follow the following steps:

 1. rm -rf node_modules package-lock.json
 2. npm install @angular-devkit/schematics@8
 3. ng update @angular/core@8 @angular/cli@8
 4. ng update @angular/core@9 @angular/cli@9

In case you face any Peer dependency warnings when running the commands above run npm uninstall affected_package_name and then run the steps below:

 1. npm i
 2. ng update @angular/core@8 @angular/cli@8
 3. ng update @angular/core@9 @angular/cli@9
 4. npm i compatible_affected_package_name

You can run npm uninstall @angular-devkit/schematics after successful update.

Note: Always follow the Angular update Guide. You can swap the current and target angular versions depending on your situation. Before moving to higher versions ensure that all of your dependencies can work on your target version.

Solution 5 - Angular

Got this running after a bomb-out due to a --force being required.

The previous ng update had got so far and had deleted node_modules.

Had to reset branch and npm ci first before running with ng update with the --force.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshayanmalindaView Question on Stackoverflow
Solution 1 - AngulareagorView Answer on Stackoverflow
Solution 2 - AngularNimezzzView Answer on Stackoverflow
Solution 3 - AngularatconwayView Answer on Stackoverflow
Solution 4 - AngularHamfriView Answer on Stackoverflow
Solution 5 - Angularjenson-button-eventView Answer on Stackoverflow