5

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.

9
  • @downvoter that would be nice to explain what is wrong.
    – hzitoun
    Commented Jan 7, 2019 at 13:44
  • You'll have a depreciation warning or a version mismatch error if the packages are out of sync. That should answer your question.
    – user4676340
    Commented Jan 7, 2019 at 13:46
  • And to "install a version" of the core module, simply create a new project with ng new XXX, the CLI will handle the dependencies.
    – user4676340
    Commented Jan 7, 2019 at 13:47
  • 2
    @trichetriche The question is actually well founded since different versions of the CLI can cause problems since they do different things, especially between majors
    – mchl18
    Commented Jan 7, 2019 at 15:00
  • 1
    @trichetriche It is logic as there's no tool or docs about compatability between cli and core. Commented Jan 7, 2019 at 15:30

2 Answers 2

2

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.

0

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.