Resolved: Angular 9 to Angular 10+ This version of CLI is only compatible with the Angular version but angular version was found instead
This version of CLI is only compatible with Angular versions 0.0.0 || ^10.0.0-beta || >=10.0.0 <11.0.0,
but Angular version 9.1.13 was found instead.
Issue Description
Angular CLI ng build command gives below error,
ng build
- Angular 10 error
This version of CLI is only compatible with Angular versions 0.0.0 || ^10.0.0-beta || >=10.0.0 <11.0.0,
but Angular version 9.1.2 was found instead.
- Angular 9 error
This version of cli is only compatible with angular versions ^9.0.0-beta || >=9.0.0 <10.0.0, but angular version 8.2.14 was found instead
- Angular 8 error
This version of CLI is only compatible with angular versions ^8.0.0-beta =8.0.0 <9.0.0 but Angular version 6.1.10 was found instead.
Resolution
This error I found to be due to the difference in Angular CLI installed globally Vs local project workspace.
This error is most visible when you are trying to migrate an older Angular framework (Example- Angular 5 or 6 or 7 or 8 apps to Latest (Ex. Angular 9 or 10).
If you need to perform any old framework migration like Angular 6 or 7 then you must migrate the application to Angular 8 first and use the below steps explained to complete the migration Angular 9 or 10
Steps to fix the issue
Below are generic steps to fix the issue which can be followed for this or similar such issues,
- Update Angular CLI for a workspace (Local)
npm install --save -dev @angular/cli@latest
Or
The above command is obsolete from Angular 9 and onwards. Please use the below commands for angular 9 and 10 onwards,
npm install --save --only=dev @angular/cli@latest
Note: Make sure to install the global version using the command with ‘-g’ is if it installed properly.
npm install -g @angular/cli@latest
- Run Update command to get a list of all dependencies required to be upgraded.
ng update
Example:
- Next Run update command as below for each individual Angular core package
ng update @angular/cli @angular/core
However, I had to add ‘–force’ and ‘–allow-dirty’ flags command additionally to fix all other pending issues.
ng update @angular/cli @angular/core --allow-dirty
Or
ng update @angular/cli @angular/core --allow-dirty --force
Build the project,
Finally, the build is successful.
Reference : codebuzz
Did I miss anything else in these resolution steps? Did the above steps resolve your issue?
Please provide your feedback in the comments below!