Today in this article, we will cover a few easy steps to resolve common errors in angular like “This version of cli is only compatible with angular versions“.
Issue Description
Angular CLI ng build command gives the below error,
ng build
Angular 14 or 15 error
This version of cli is only compatible with angular versions ^14.0.0-next || >=14.0.0 <15.0.0, but angular version 14.0.00 was found instead.
Resolution
This error I found to be due to the difference in Angular CLI installed globally Vs local project workspace followed by incompatible versions of angular libraries.
Steps to fix the issue
Below are generic steps to fix the issue which can be followed for this or similar issues,
Step 1- Use the correct Node version
Make sure you are using Node 10.13 or later.
Step 2 – Update Angular CLI for a workspace
npm install -g @angular/cli
Note: Make sure to install the global version using the command with ‘-g’ to install properly.
Step 3 – Ng Update – Update Angular Core Packages in the Project
Run the Update command to get a list of all dependencies required to be upgraded.
ng update
Next, Run the update command below for each Angular core package,
To use the current stable release of the core framework and CLI by running the following command.
ng update @angular/cli @angular/core
However, I had to add ‘–force‘ and ‘–allow-dirty‘ flag commands additionally to fix all other pending issues.
So if needed please execute the command below,
ng update @angular/cli @angular/core --allow-dirty
Step 4 (Optional ) – Updating to the major version
ng update @angular/cli@^<major_version> @angular/core@^<major_version>
Example
If you are already on version 14 and want to migrate to Angular version 15, you can specify the major version below,
ng update @angular/cli@^15 @angular/core@^15
Build the project,
Finally, the build is successful.
Still can not resolve the issue?
If you are still facing issues, try cleaning and reinstalling the node_modules
directory.
Command
rm -rf node_modules
npm install
You could also try uninstalling the angular CLI version and reinstall it,
npm uninstall -g @angular/cli
npm cache clean --force
Angular version upgrade – Guidelines
If you need to perform any old framework migration like Angular 12 to more Angular 15 then, you must first migrate to Angular 13 then 14, and finally 15 to avoid any migration issues.
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 onwards untill the latest framework migration.
Reference:
Did I miss anything else in these resolution steps? Did the above steps resolve your issue?
Please sound off in the comments below!
Watch this 3-minute Video Tutorial for any issues.
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.
Thank you for the solution, my project is working now
Hey Ninoos, Glad that it helped you! Cheers.
Thanks a lot , it really worked for me.
Worked perfectly. Thanks
Hey Abel, Thanks. Glad it helped you fix the issue!
Brilliant, clear walkthrough. Thanks!
Worked for me .Thank you !
Hey it didn’t worked at the ng build step
I got the following error
An unhandled exception occurred: The src/assets asset path must start with the project source root.
See “/private/var/folders/nb/ghn0h64n7mlcctd4qk3z4n0r0000gp/T/ng-uK0Oad/angular-errors.log” for further details.
Hey Lakshmi – Could you confirm your Angular CLI version you have used? Could you please delete cache using commands npm cache clean –force. Hope you have followed migration guidelines .Hope that helps. Please let me know if you face any issues.
Thanks for the Article.Great article and It will help me on Great way.
Thanks Mahanta,Glad you liked it!
It doesnt work for me.
cmd showed me err like this
”
An unhandled exception occurred: Error: ENOENT: no such file or directory, lstat ‘C:/Users/localUser/Desktop/hxDev/myGitProj/LearningAngular/tsconfig.app.json’
“
Hello Lysander- Could you check the path of tsconfig.app.json is correct in the Angular.json file?
This could be a path issue,
[cc lang=”html”]”projects”: {
“my-app”: {
“projectType”: “application”,
..
..
“sourceRoot”: “src”,
“prefix”: “app”,
“architect”: {
“build”: {
…
..
..
“tsConfig”: “tsconfig.app.json”,
“aot”: false,[/cc]
Very useful , thank you champ.
Thanks schroodinger.
thank you very much
Thanks Nadezda.
Thanks. It resolved my issue
Thanks Rocky. Glad it helped you!
Thanks you ..helped me to fix the issue
Thank you. This work!.
Thanks, Peera for confirming! I appreciate your time.
Thank you for helpful steps.
Thanks Elias for the confirmation.
Thanks . Worked for me for Angular 4 to 8 migration.