ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead
AngularTypescriptNpmAngular CliAngular Problem Overview
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?
Angular Solutions
Solution 1 - Angular
To fix this install the specific typescript version 3.1.6
npm i typescript@3.1.6 --save-dev --save-exact
Solution 2 - Angular
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"
Solution 3 - Angular
First install your targeted version
npm i typescript@3.1.6 --save-dev --save-exact
Then before compiling do
npm i
Solution 4 - Angular
If you want to use Angular with an unsupported TypeScript version, add this to your tsconfig.json
to ignore the warning:
"angularCompilerOptions": {
"disableTypeScriptVersionCheck": true,
},
Solution 5 - Angular
npm install typescript@">=3.1.1 <3.3.0" --save-dev --save-exact
rm -rf node_modules
npm install
Solution 6 - Angular
> 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:
- Delete
node_modules
folder - Run
yarn install
ornpm install
- Compile and cross your fingers xD
Solution 7 - Angular
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 [email protected] --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
Solution 8 - Angular
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
Solution 9 - Angular
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: https://stackoverflow.com/questions/43931986/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