Angular Compiler需要TypeScript> = 2.7.2和<2.8.0,但是找到了2.8.3

问题描述 投票:30回答:9

我开始在我的Angular应用程序上收到此错误:

Angular Compiler需要TypeScript> = 2.7.2和<2.8.0,但是找到了2.8.3

当我尝试将打字稿降级到正确版本时:

npm install -g [email protected]它说更新1包。

当我使用npm view typescript version验证打字稿版本时,我仍然得到2.8.3

我甚至尝试使用npm uninstall -g typescript完全删除打字稿

但当我再次验证打字稿版本npm view typescript version我仍然得到2.8.3

有哪些命令可以正确地清除和恢复先前版本(例如2.7.2)的打字稿?

我正在运行节点v10.0.0和npm v6.0.1

当我运行npm list -g typescript时,我看到2.7.2的正确版本,但仍然以某种方式全局安装2.8.3版本

angular typescript npm version global
9个回答
39
投票

你应该做npm install typescript@'>=2.7.2 <2.8.0'。这将安装您的项目所需的正确打字稿。确保在Angular项目中运行此项。

在Windows上,您应该使用双引号而不是单引号,如下所示:

npm install typescript@">=2.7.2 <2.8.0"

否则,你会得到The system cannot find the file specified.


10
投票

在您的项目文件夹中再次运行npm install [email protected],如下所示:

Want to upgrade project from Angular v5 to Angular v6

然后它应该工作。


5
投票

我做了下一步:

  • 删除了package-lock.json;
  • npm install -g --save [email protected];
  • npm uninstall -g --save [email protected];
  • 在package.json中,“devDependencies”部分用typescript更新字符串为“typescript”:“~2.7.2”。

毕竟以上运行在项目的终端ng服务 - 开(我一直在使用IDEA 2018.1)。


2
投票

我做了以下事情:

  • 手动删除文件夹node_modules
  • 手动删除文件package-lock.json
  • 在package.json文件中,请务必将TypeScript的依赖关系设置为 "typescript": "2.7.2"
  • 运行npm cache clean -f
  • 运行npm install

这对我有用。


1
投票

安装“@ angular / compiler-cli”:“7.0.0-beta.4”解决了这个问题。我使用“typescript”:“3.0.3”。


1
投票

要升级,请在终端中运行以下命令。

  • 安装最新版本的NPM npm install npm@latest -g
  • 运行审核 npm audit
  • 更新NPM npm update
  • 运行NPM运行脚本。 npm start

现在你的编译器准备好了。


0
投票

降级到typescript 2.9.2 (npm install [email protected])re-running ng update --all仍然会产生错误(两次):

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.

0
投票

在更新到macOS Mojave之后有同样的问题(在许多其他问题中)。通过手动删除node_modules和package_lock.json来修复它,将package.json中的“typescript”:“~2.7.2”更改为“typescript”:“~2.8.0”并运行npm install。


0
投票

这只是因为在你的项目中package.json文件有

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

并且在你的机器中安装了角度cli有"typescript": "2.7.2"版本。

你可以通过ng -vng v查看。

所以,只需打开package.json更新你的打字稿版本和run npm install就可以了。

© www.soinside.com 2019 - 2024. All rights reserved.