The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3 was found instead

58,062

Solution 1

You should do npm install typescript@'>=2.7.2 <2.8.0'. This will install the correct typescript your project needs. Make sure you run this inside your Angular project.

On Windows, you should use double quotes instead of single quotes, like so:

npm install typescript@">=2.7.2 <2.8.0"

Otherwise, you'll get The system cannot find the file specified..

Solution 2

In your project folder run again npm install [email protected] as stated from here:

Want to upgrade project from Angular v5 to Angular v6

Then it should work.

Solution 3

I did next steps:

  • removed package-lock.json;
  • npm install -g --save [email protected];
  • npm uninstall -g --save [email protected];
  • in package.json, section "devDependencies" updated string with typescript as "typescript": "~2.7.2".

After all above run in project's terminal ng serve --open (I've been using IDEA 2018.1).

Solution 4

I did the following:

  • Delete manually the folder node_modules
  • Delete manually the file package-lock.json
  • In the file package.json be sure to set the dependence of TypeScript as

     "typescript": "2.7.2"
    
  • run npm cache clean -f

  • run npm install

That work for me.

Solution 5

Installing "@angular/compiler-cli": "7.0.0-beta.4" resolved this issue. I use "typescript": "3.0.3".

Share:
58,062
guilhebl
Author by

guilhebl

Updated on July 22, 2022

Comments

  • guilhebl
    guilhebl almost 2 years

    I starting getting this error on my Angular app:

    The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3 was found instead

    and when I try to downgrade typescript to the right version doing:

    npm install -g [email protected] it says updated 1 package.

    when I verify typescript version using npm view typescript version I still get 2.8.3

    I even tried removing typescript entirely using npm uninstall -g typescript

    but when I verify typescript version again npm view typescript version I still get 2.8.3

    What are the commands to properly purge and restore typescript to a previous version such as 2.7.2?

    I'm running node v10.0.0 and npm v6.0.1

    When I run npm list -g typescript I see the correct version coming 2.7.2 but still version 2.8.3 is installed somehow globally

  • guilhebl
    guilhebl almost 6 years
    I tried that command before but my version still says typescript 2.8.3
  • DarkNeuron
    DarkNeuron almost 6 years
    Please save your typescript dependencies as dev dependencies; otherwise you'll be bundling typescript into your final product.
  • Jeremy Thille
    Jeremy Thille almost 6 years
    This command gives me The system cannot find the file specified.
  • myhouse
    myhouse almost 6 years
    You need to run that inside your project.
  • Zarepheth
    Zarepheth almost 6 years
    Depending upon your operating system and perhaps your settings, you may need to use double-quotes instead of single quotes: npm install -g typescript@">=2.7.2 <2.8.0"
  • Jette
    Jette almost 6 years
    I had 2.7.2 installed globally but got 2.9.2 locally after an update with npm-check-updates. So I just followed your steps omitting the -g option, and now I am able to build my project again. Nice! :-)
  • Sharp
    Sharp over 5 years
    I have to defend this solution. This is the only one which consistently works for me.