53

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 typescript@2.7.2 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
  • 8,330
  • 10
  • 47
  • 66
  • Stuck with same issue. I'm running 'ng build' from a Jenkinsfile, and it ends up with typescript 2.9.2. My guess is that it's related to @angular-devkit/build-optimizer having a dependency on typescript ~2.9.1. – Simon Jun 23 '18 at 13:30
  • Just found out about this question. If anyone has faced a similar error on other versions, please refer to my post! https://stackoverflow.com/questions/57216110/the-angular-compiler-requires-typescript-3-4-0-and-3-5-0-but-3-5-3-was-found/57216166#57216166 – wentjun Mar 19 '20 at 03:25

9 Answers9

76

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..

Eliya Cohen
  • 10,716
  • 13
  • 59
  • 116
myhouse
  • 1,911
  • 1
  • 17
  • 24
10

In your project folder run again npm install typescript@2.7.2 as stated from here:

Want to upgrade project from Angular v5 to Angular v6

Then it should work.

knnhcn
  • 1,071
  • 1
  • 11
  • 22
5

I did next steps:

  • removed package-lock.json;
  • npm install -g --save typescript@2.7.2;
  • npm uninstall -g --save typescript@2.9.2;
  • 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).

  • 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! :-) – Jette Jul 25 '18 at 11:34
2

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.

Andres SoN
  • 41
  • 4
  • 2
    I have to defend this solution. This is the only one which consistently works for me. – Sharp Oct 29 '18 at 08:40
1

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

Demven Weir
  • 807
  • 7
  • 6
1

To upgrade, run the following commands in the terminal.

  • Install the latest version of NPM

    npm install npm@latest -g
    
  • Run audit

    npm audit  
    
  • Update the NPM

    npm update
    
  • Run the NPM run script.

    npm start
    

Now your compiler is ready.

Dale K
  • 25,246
  • 15
  • 42
  • 71
0

Downgrading to typescript 2.9.2 (npm install typescript@2.9.2) and re-running ng update --all still yields the error (twice):

Package "@angular/compiler-cli" has an incompatible peer dependency to "typescript" (requires ">=2.7.2 <2.10", would install "3.1.3"
Verified that version 2.9.2 of typescript was in node_modules.
Rarblack
  • 4,559
  • 4
  • 22
  • 33
Vipisanan
  • 1
  • 1
0

Had the same issue (amongst many others) after updating to macOS Mojave. Fixed it by removing node_modules and package_lock.json manually, changed in package.json from "typescript": "~2.7.2" to "typescript": "~2.8.0" and ran npm install.

bakke2ooo
  • 1
  • 2
0

This is just because in your projects package.json file has

eg."devDependencies": {"typescript": "~2.8.3" }

and in your machine where angular cli installed has "typescript": "2.7.2" version.

You can check this by ng -v or ng v.

So, just open package.json update your typescript version and run npm install and you are done.

Deva
  • 1,851
  • 21
  • 22