Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 351
guilhebl Avatar asked May 22 '18 07:05

guilhebl


People also ask

What version of TypeScript does angular use?

Angular now uses TypeScript 3.4.

What version of TypeScript does angular 8 use?

Angular 8 supports the TypeScript 3.4 or above version. So, if we want to use Angular 8 for our application, then we need to first upgrade the TypeScript to 3.4 or above.

Do we need to install TypeScript for angular?

Knowledge of TypeScript is helpful, but not required. Angular requires an active LTS or maintenance LTS version of Node.js. For information about specific version requirements, see the engines key in the package.json file. For more information on installing Node.js, see nodejs.org.

What version of TypeScript does angular 6 use?

Angular 6 works on the same structure as Angular4 but is faster when compared to Angular4. Angular6 uses TypeScript 2.9 version whereas Angular 4 uses TypeScript version 2.2. This brings a lot of difference in the performance. To install Angular 6, the Angular team came up with Angular CLI which eases the installation.


3 Answers

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

like image 193
myhouse Avatar answered Oct 16 '22 23:10

myhouse


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.

like image 10
knnhcn Avatar answered Oct 16 '22 23:10

knnhcn


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

like image 5
Ilya Afanasyev Avatar answered Oct 16 '22 23:10

Ilya Afanasyev