我开始在我的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版本
你应该做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.
。
在您的项目文件夹中再次运行npm install [email protected]
,如下所示:
Want to upgrade project from Angular v5 to Angular v6
然后它应该工作。
我做了下一步:
毕竟以上运行在项目的终端ng服务 - 开(我一直在使用IDEA 2018.1)。
我做了以下事情:
"typescript": "2.7.2"
这对我有用。
安装“@ angular / compiler-cli”:“7.0.0-beta.4”解决了这个问题。我使用“typescript”:“3.0.3”。
要升级,请在终端中运行以下命令。
npm install npm@latest -g
npm audit
npm update
npm start
现在你的编译器准备好了。
降级到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.
在更新到macOS Mojave之后有同样的问题(在许多其他问题中)。通过手动删除node_modules和package_lock.json来修复它,将package.json中的“typescript”:“~2.7.2”更改为“typescript”:“~2.8.0”并运行npm install。
这只是因为在你的项目中package.json
文件有
eg."devDependencies": {"typescript": "~2.8.3"
}
并且在你的机器中安装了角度cli有"typescript": "2.7.2"
版本。
你可以通过ng -v
或ng v
查看。
所以,只需打开package.json更新你的打字稿版本和run npm install
就可以了。