Angular "This version of CLI is only compatible with Angular versions" in CI
The Angular CLI checks that its major version matches @angular/core. When a globally installed or mismatched CLI runs against a project on a different major, it refuses with a compatibility error.
What this error means
ng build or ng test stops with "This version of CLI is only compatible with Angular versions ^X, but Angular version Y was found instead".
This version of CLI is only compatible with Angular versions ^17.0.0,
but Angular version 16.2.0 was found instead.
Please visit https://update.angular.io/ ...Common causes
A global CLI shadows the project CLI
A globally installed @angular/cli on a different major runs instead of the project-local one, so the versions disagree.
The project CLI and core are on different majors
A partial upgrade left @angular/cli and @angular/core on different majors in package.json.
How to fix it
Run the project-local CLI
- Invoke the CLI through
npxorpackage.jsonscripts so the local version is used. - Avoid relying on a globally installed
ng. - Re-run the build.
npx ng build # uses the project-local CLI, not a global oneAlign CLI and core majors
Bring @angular/cli and @angular/core to the same major and reinstall.
npm install -D @angular/cli@17
npm install @angular/core@17How to prevent it
- Always run
ngvianpxor npm scripts in CI, never a global install. - Upgrade CLI and core together to the same major.
- Commit the lockfile so CLI and core versions are pinned.