Problem upgrading Angular 14 to Angular 16. npm installs angular v17 automatically

381 Views Asked by At

I have a project with Angular 14 that needs to be updated to the current Angular LTS version (for today is Angular 16). I did all steps and was able to resolve manually, but I would like to know what step I did wrong to avoid it for next time.

My steps:

  1. Run ng update command which offers me modules that should be updated. 111
  2. Then I run ng update @angular/cdk@15 @angular/cli@15 @angular/core@15 @angular/material@15 --force. I used force flag to avoid all conflicts and resolve all my problems. For some reason angular decided to install compiler v16. I wondered why he is doing that when I specified v15. But because it's intermidiate step I decided to move on. 222
  3. Commited.
  4. Used ng update command again to see my next steps.For some reason here, Angular decided to offer me update angular/core to v 17. 333
  5. Run command ng update @angular/cdk@16 @angular/cli@16 @angular/material@16. I skipped updating core, becuase it's definitely wrong step. But as you can see npm installed angular-compiler v17 anyway. I'm not sure why npm pushes to install angular v17 when I strictly specified v16. 444
  6. As result it installed Angular v17 and won't let me build. 555

I was able to resolve the problem by downgrading versions (from 17 to 16) in package.json. But I don't think that it's a good way to do it.

I read other posts and watched youtube videos to see how other people doing and I don't see where I did mistake that caused to install Angular v17.

Any guidance will be helpful.

1

There are 1 best solutions below

1
geekieshpixel On

I faced the same issue. This is how I fixed it...

You need to check which version of angular cli is installed globally and if it is compatible with current node version installed in your system. If you have multiple node versions installed, then you can use nvm to switch between node versions.

eg. If you are trying to migrate from v14 to v15, before hitting ng update command you need to check the node version that is being used in current directory where angular update is going to take place. and secondly, check if your global angular cli >= the version you are going to update to.

Refer this to check compatibility. https://angular.io/guide/versions

And to answer why it skipped v15 and updated to v16... One of reason could be your existing node version being incompatible with version 15 of angular.