The Angular Compiler requires TypeScript >=2.7.2 a

2020-02-17 09:00发布

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

9条回答
戒情不戒烟
2楼-- · 2020-02-17 09:29

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

查看更多
啃猪蹄的小仙女
3楼-- · 2020-02-17 09:30

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.

查看更多
Root(大扎)
4楼-- · 2020-02-17 09:30

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

查看更多
登录 后发表回答