178

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.
atconway
21.3k33 gold badges167 silver badges239 bronze badges
asked Sep 2, 2019 at 4:58
1
  • ng update @angular/cli @angular/core --allow-dirty. This doesn't seem to exist anymore in 8.0.0, although it's still in their documentation, ng update --help has no mention of it and I've tried --allow-dirty/--allowDirty. I unfortunately had to commit and then undo that commit. Commented Sep 2, 2019 at 5:10

8 Answers 8

363

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

answered Mar 20, 2020 at 9:14
Sign up to request clarification or add additional context in comments.

3 Comments

Yes to update a project, all the packages have to be installed beforehand. Found out by trial and error. Thanks!
node_modules might also annoyingly disappear if ng update fails for some reason.
I was in the wrong folder. Oops.
46

First commit all your changes to the repo and then try following commands.

npm i -g @angular/[email protected]

and

ng update --all --force

Please read this issue on github

answered Sep 2, 2019 at 7:02

4 Comments

Starting with Angular 13 --all is deprecated
@DragosStoica any alternative solution?
I'm using 'npx npm-check-updates -u' command (you need to install the 'npm-check-updates' package first)
> ng update --all --force Error: Unknown argument: all
21

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.

answered Oct 30, 2019 at 3:49

Comments

12

Assuming you are upgrading 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.

answered May 26, 2021 at 15:15

1 Comment

thanks. helped me a lot. also need to install @angular/cli if not exist in package,json.
5

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.

answered Feb 26, 2022 at 10:28

Comments

4
  1. "Repository is not clean" means you have changes that needs to be commited or stashed.

  2. "Package '@angular/cli' is not a dependency." to fix run npm install in your project directory.

One of the reason angular cli can not be updated might be the minimum node.js version is not met. The lastest angular cli (v14 at the time of writing) requires nodejs version of the v14 or above. In that case you have to do the following:

nvm i v14
ng update @angular/cli @angular/core
ng v (to check angular cli version)
answered Jul 20, 2022 at 11:58

1 Comment

--allow-dirty helps to migrate even repo is dirty.
0

You might be missing @angular/cli dependency in your package.json file. Add proper version of @angular/cli to package.json. And then run npm install. Commit your changes.

After that ng update @angular/cli @angular/core should work properly.

answered Feb 20, 2023 at 10:05

Comments

0

You might also have to periodically check that the node_modules folder looks right from time to time. IE, you should see dependencies in there, and not a .staging folder.

A scenario I just encountered was successfully updating @angular/core @angular/cli. then I tried to upgrade @angular/material but couldn't. Turns out my node_modules folder somehow never finished an install. So I had to run

npm install --force

Commit my changes, then I could finally proceed with

ng update @angular/material

Long story short: with each successful install/update,

  1. check that the package.json looks right with the correct version number of whatever you just updated
  2. Make sure node_modules looks right (doesn't just have a .staging folder in it) - if not, run npm install or npm install --force
  3. If you're already in a .git repo, add and commit your current changes.
answered Sep 14, 2023 at 16:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.