Angular-cli: Angular CLI compiler requires older Typescript

Created on 8 Sep 2017  Â·  22Comments  Â·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.4.0
node: 8.4.0
os: darwin x64
@angular/animations: 4.3.6
@angular/cdk: 2.0.0-beta.10
@angular/common: 4.3.6
@angular/compiler: 4.3.6
@angular/core: 4.3.6
@angular/forms: 4.3.6
@angular/http: 4.3.6
@angular/material: 2.0.0-beta.10
@angular/platform-browser: 4.3.6
@angular/platform-browser-dynamic: 4.3.6
@angular/router: 4.3.6
@angular/cli: 1.4.0
@angular/compiler-cli: 4.3.6
@angular/language-service: 4.3.6
typescript: 2.5.2

Repro steps.

Start up app with ng serve and this message is displayed:

@angular/[email protected] requires typescript@'>=2.1.0 <2.4.0' but 2.5.2 was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.

Please run the following command to install a compatible version of TypeScript.

    npm install typescript@'>=2.1.0 <2.4.0'

To disable this warning run "ng set --global warnings.typescriptMismatch=false".
RFC / discussion / question

Most helpful comment

These versions shown in the warning are the ones recommended by the Angular team.

A lot of bugs that are reported are actually the result of using incompatible versions, and it is not clear at all what these versions are. This is not a new restriction: incompatible versions have caused problems for a while now.

It is true that other typescript versions may work in your particular project - but we cannot guarantee they will work. That is why we show a warning now (but not an error).

It became more important to alert users to what the recommended versions are because Angular version 5 is coming out and it has its own recommend set of typescript versions.

There are two factors preventing simply adding a strict dependency:

  • the CLI must support Angular versions 2, 4, and 5
  • Angular itself does not have a dependency/peer dependency on typescript

So it was better to show a warning than to prevent usage of other typescript versions. If you feel confident that your project should work with other versions of typescript, you can disable the warning. This is useful when using versions of libraries that specifically need typescript of a certain version for compilation to be successful.

All 22 comments

Based on that commit it should allow 2.5+ but I have same issue even with 2.4.2 and angular 4.3.6

UPDATE: Based on that sounds like typescript: '>=2.4.0 <2.6.0' required angular compiler '>=5.0.0 <6.0.0'

Newly created project with [email protected] requires typescript@~2.3.3

Is this requirement valid? My project looks fine with [email protected] and I was planning to go for 2.5.x but now I am not sure if it is a good idea.

Anyway it would be good if @angular/compiler-cli would define the correct peer dependency here: https://github.com/angular/angular/blob/4.4.x/packages/compiler-cli/package.json#L17. Not everybody is using angular-cli. I can understand the safety check, but I am not sure the matrix linked by kuncevic should be the correct place to specify the requirements.

There were no indications that this restriction would be implemented. The only thing I updated in my project was the CLI. The @angular/[email protected] has no problems previously.

These versions shown in the warning are the ones recommended by the Angular team.

A lot of bugs that are reported are actually the result of using incompatible versions, and it is not clear at all what these versions are. This is not a new restriction: incompatible versions have caused problems for a while now.

It is true that other typescript versions may work in your particular project - but we cannot guarantee they will work. That is why we show a warning now (but not an error).

It became more important to alert users to what the recommended versions are because Angular version 5 is coming out and it has its own recommend set of typescript versions.

There are two factors preventing simply adding a strict dependency:

  • the CLI must support Angular versions 2, 4, and 5
  • Angular itself does not have a dependency/peer dependency on typescript

So it was better to show a warning than to prevent usage of other typescript versions. If you feel confident that your project should work with other versions of typescript, you can disable the warning. This is useful when using versions of libraries that specifically need typescript of a certain version for compilation to be successful.

@filipesilva : Thanks for the high-level explanation.

For those of us who wish to "scout ahead" using TypeScript versions beyond what is recommended, is there a place where any known issues (with or without a fix/work-around) have been documented?

@filipesilva See also #7678 which would help a lot related to the warning.

Hi guys...
Having the same issue with @angular/[email protected]

Node: 8.4.0
Typescript: 2.5.2

But as we can see in the package.json of angular/compiler-cli, it saids, in its peerDependencies, that it needs typescript ^2.0.2, and [email protected] should meet this requirement

Maybe the dependencies on typescript should be a peerDependencies?

A CLI project may now cause more confusion:

```

  • node_modules
    |- @angular
    |- cli
    |- node_modules
    |- typescript # <- 2.5.x (from cli package.json >=2.0.0 < 2.6.0)
    |- typescript # <- 2.4.x (from package.json)
    package.json

In my case I am quite used to work with the spread operator, also using it to pass parameters to functions, and I need to use Typescript@>=2.4.0 to compile a project created with Angular CLI 4.3.6, as this issue was resolved in TypeScript 2.4 Microsoft/TypeScript#5296.

But the reasoning given is quite valid, and you can upgrade TypeScript per project to see if it fits for you or not.

Thanks, and keep the good work team :heart:

@dherges that's actually a limitation of the CLI architecture currently... the CLI (specifically ngtools/webpack) really wants to use the local project typescript, but the global CLI doesn't have a local project and thus it would have missing peerdeps.

The answer is, of course, to have two CLI packages: one for global and one for local, installing different dependencies. This is a goal for CLI 2.0, but would be disruptive now so we don't do it.

Would the global CLI pick up a global typescript as peerDep?

Cheers, David

On 2. Oct 2017, at 12:29, Filipe Silva notifications@github.com wrote:

@dherges that's actually a limitation of the CLI architecture currently... the CLI (specifically ngtools/webpack) really wants to use the local project typescript, but the global CLI doesn't have a local project and thus it would have missing peerdeps.

The answer is, of course, to have two CLI packages: one for global and one for local, installing different dependencies. This is a goal for CLI 2.0, but would be disruptive now so we don't do it.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

It would, but asking people to install both the cli and typescript globally isn't a good solution either imho.

Is it right, that anguilar cli now uses the typescript version installed ion the user's project workspace?

fix(@angular/cli): remove typescript dependency
a28a967

8185

@dherges it almost always did, except when the dependency wasn't hoisted. That PR is meant to address that case.

It seems this is still the case today that the latest Angular Compiler requires an older version of TypeScript, but just the compiler. I mean we are talking minor version limitations not major versions this seems odd. It should require just a min or greater version and block the next major version.

Currently today you get this error:

The Angular Compiler requires TypeScript >=3.1.1 and <3.3.0 but 3.4.5 was found instead.

Seem like it should just require TypeScript >=3.1.1 and <4.0.0 until there is a broken minor release which would hopefully be rare.

Should we just always assume that if we want to use the latest stable release of Angular we always have to run versions behind the latest stable version of Typescript?

@CreepyGnome, Typescript minor version can be breaking and that's why we only support versions that have been released.

Currently, it doesn't support anything newer than 3.2.4 and there have been other released versions since then. The current released version is Typescript 3.4.5.

So based on your statement shouldn't Typescript 3.4.5 be supported then?

It is supported in version 8 release candidate.

Closing the initial reported issue should be solved by now.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericel picture ericel  Â·  3Comments

gotschmarcel picture gotschmarcel  Â·  3Comments

donaldallen picture donaldallen  Â·  3Comments

JanStureNielsen picture JanStureNielsen  Â·  3Comments

daBishMan picture daBishMan  Â·  3Comments