177

I am getting this error

ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead.

Seems like Typescript updated but the Angular Compiler doesn't like that.

How do I fix this?

carkod
  • 1,844
  • 19
  • 32
Matt
  • 33,328
  • 25
  • 83
  • 97
  • 2
    Either downgrade typescript or upgrade angular – ShamPooSham Dec 02 '18 at 07:50
  • 1
    Angular 7 fixed this issue. I guess your version of Angular is 6. – carkod Dec 21 '18 at 18:40
  • Just realised quite a few people have raised questions similar to this one. Just wanna put a link to my answer over here as I felt that it sufficiently answers it https://stackoverflow.com/a/57216166/10959940 – wentjun Jan 02 '20 at 18:59

9 Answers9

221

To fix this install the specific typescript version 3.1.6

npm i typescript@3.1.6 --save-dev --save-exact
Matt
  • 33,328
  • 25
  • 83
  • 97
  • 1
    before that, I had to update my node.js and npm versions on my system to get it work – Pipo Dec 21 '18 at 20:41
  • Does anyone know what updated the typescript version to 3.2.x in the first place? Is it because that just happens to be the newest version today - and something in my package file that required it is 'unconstrained' so it allowed the update - but Angular's 'allowed' version maxes out at <3.2? Is that why? – Simon_Weaver Dec 31 '18 at 01:17
  • I got myself confused about which angular version supported TS 3.2. The first version is 7.2.0 which is currently in RC0 status, and therefore didn't update to that version by itself. – Simon_Weaver Dec 31 '18 at 01:52
  • This is the solution to update node end ts version. Thanks – Anoj Jul 22 '21 at 19:43
162

In my case below command worked for windows. It will install latest required version between 3.1.1 and 3.2.0. Depending on OS use either double or single quotes

npm install typescript@">=3.1.1 <3.2.0" 
Sebastian Viereck
  • 5,455
  • 53
  • 53
Sushil Jadhav
  • 2,217
  • 2
  • 19
  • 33
  • 9
    Just had this happen to me (Angular 7.3.2 but Debian has Typescript 3.3.1 now) and this answer is nicest because I don't need to work out what is the most recent version that meets the criteria Angular provides. – karora Feb 10 '19 at 11:40
  • 2
    npm install typescript@">=3.2.0 <3.3.0" – Luke Feb 19 '19 at 09:24
  • 1
    For Mac worked like npm install typescript@'>=3.1.1 <3.3.0' – Inês Gomes May 07 '19 at 07:57
  • 6
    Worked for me :) I used **npm install typescript@">=3.4.0 and <3.5.0" --save-dev --save-exact** – Naveen Kumar V Jul 02 '19 at 12:43
30

If you want to use Angular with an unsupported TypeScript version, add this to your tsconfig.json to ignore the warning:

  "angularCompilerOptions": {
    "disableTypeScriptVersionCheck": true,
  },
Tereza Tomcova
  • 4,928
  • 4
  • 30
  • 29
27

First install your targeted version

npm i typescript@3.1.6 --save-dev --save-exact

Then before compiling do

   npm i
Sudheer Muhammed
  • 813
  • 8
  • 10
18
npm install typescript@">=3.1.1 <3.3.0" --save-dev --save-exact
rm -rf node_modules
npm install
yeyeyerman
  • 7,751
  • 7
  • 43
  • 52
8

ERROR in The Angular Compiler requires TypeScript >=3.4.0 and <3.6.0 but 3.6.3 was found instead.

For this error you can also define a version range:

yarn add typescript@">=3.4.0 <3.6.0" --save-dev --save-exact

or for npm

npm install typescript@">=3.4.0 <3.6.0" --save-dev --save-exact

After installing the correct typescript version:

  1. Delete node_modules folder
  2. Run yarn install or npm install
  3. Compile and cross your fingers xD
Florian Leitgeb
  • 15,657
  • 6
  • 31
  • 40
4

Got a similar error from CircleCi's error log.

"ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.3.0 but 3.3.3333 was found instead."

Just so you know this did not affect the Angular application, but the CircleCi error was becoming annoying. I am running Angular 7.1

I ran: $ npm i typescript@3.1.6 --save-dev --save-exact to update the package-lock.json file.

Then I ran: $ npm i

After that I ran: $ npm audit fix

"This CircleCi error message" went away. So it works

1

For following Error:

ERROR in The Angular Compiler requires TypeScript >=3.4.0 and <3.6.0 but 3.6.3 was found instead.

Run following NPM command:

$ npm install typescript@3.5.3

Source Link

Code Spy
  • 9,626
  • 4
  • 66
  • 46
  • 2
    A better approach would be to give him the range: `yarn add typescript@">=3.4.0 <3.6.0" --save-dev --save-exact` or with npm `npm install typescript@">=3.4.0 <3.6.0" --save-dev --save-exact`. – Florian Leitgeb Sep 19 '19 at 09:55
1

I also faced similar issues when tried to do ng serve. I was able to resolve it as below.
Note:

C:\Windows\system32> is on windows command prompt
C:\apps\workspace\testProj>  is on VS code Terminal (can also be doable in another command prompt)

Following are the steps which I used to resolve this.

Step1. Verify the cli version installed on command prompt (will be Angular CLI global version)

C:\Windows\system32>ng --version

Angular CLI: 8.3.13

If cli was installed earlier, it shows the global cli version.

If cli was not installed, we may get the error
ng is not recognized as an internal or external command

a. (Optional Step) Install Angular CLI global version

C:\Windows\system32>npm install -g @angular/cli
C:\Windows\system32>npm install -g @angular-cli/latest

b. Check version again

C:\Windows\system32>ng --version
Angular CLI: 8.3.13

Step2. Verify the local cli version installed on your angular project(VS code ide or command prompt cd'd to your project project)

C:\apps\workspace\testProj>ng --version
Angular CLI: 7.3.8

Note: Clearly versions are not in sync. Do the following in your angular project

C:\apps\workspace\testProj>ng update @angular/cli        -> important to sync with global cli version

Note: If upgrade donot work using above command (ref: How to upgrade Angular CLI to the latest version) On command prompt, uninstall global angular cli, clean the cache and reinstall the cli

C:\Windows\system32>npm uninstall -g angular-cli
C:\Windows\system32>npm cache clean or npm cache verify #(if npm > 5)
C:\Windows\system32>npm install -g @angular/cli@latest

Now update your local project version, because cli version of your local project is having higher priority than global one when you try to execute your project.

C:\apps\workspace\testProj>rm -rf node_modules
C:\apps\workspace\testProj>npm uninstall --save-dev angular-cli
C:\apps\workspace\testProj>npm install --save-dev @angular/cli@latest
C:\apps\workspace\testProj>npm install
C:\apps\workspace\testProj>ng update @angular/cli

Step3. Verify if local project cli version now in sync with global one

C:\Windows\system32>ng --version
Angular CLI: 8.3.13

C:\apps\workspace\testProj>ng --version
Angular CLI: 8.3.13

Step4.. Revalidate on the project

C:\apps\workspace\testProj>ng serve

Should work now

vinsinraw
  • 2,003
  • 1
  • 16
  • 18