hzitoun
hzitoun

Reputation: 5832

Compatibility between Angular CLI version & Angular Core version?

Is there any way to know which Angular CLI version to install which is compatible with my Angular Core version? Are they completely independent?

Working on an existing Angular App with Core v5.2.8, I see they use CLI v6.0.8 so I was wondering which version of CLI should we use?

The compatibility between Angular CLI & Angular Core is documented nowhere.

Upvotes: 5

Views: 3880

Answers (2)

zzpzaf
zzpzaf

Reputation: 158

In short: What you need is to decide what is the appropriate Angular version (angular-core) for your project. You can see the official compatibility list here and/or here. Next, you have to ensure about the Angular CLI version.

It seems that not always an Angular CLI version matches the Angular core version. So, you have to check if the Angular selected version matches an angular-cli version, and if not, then try to locate the closer (upper, if possible, with the same major number) version. E.g.: If you wish to use Angular (i.e. angular-core) version 16.2.12, because it seems to be the last 16.x.x version, then you can select the angular-cli 16.2.11 version, since angular-cli 16.2.12 version does not exist (at least, as per Jan 13, 2024). You can find here the version history for angular-core, and here for angular-cli.

Upvotes: 0

mchl18
mchl18

Reputation: 2336

A common thing which people do is always use the global install. This can however cause inconsistencies with older projects.

The versions in your package.json should always be compatible.

To be sure you run the local version do this:

npm run -- ng generate component foo

Instead of this:

ng generate component foo

It will then always use the local version.

Yarn passes all params so it doesn't need the ugly annotation:

yarn run ng generate component foo

A good example for this is e.g. how Angular deals with service DI. Whereas in previous versions it was necessary to add each service to the app module as a provider.

This was changed in version 6 so this actually is really relevant:

In v6 and later versions of Angular the @Injectable decorator was extended with the capability which lead to a different boilerplate:

Before:

@Injectable()

After:

@Injectable({
  providedIn: 'root'
})

Thereby removing the necessity to add all services to the app module within an app.

So creating a service from CLI v6 produced a template which was not compatible with v5.

Upvotes: 2

Related Questions