我的 angular 项目运行良好,但是当我将 Angular 更新到版本 9 时,它开始给我这个错误:
This version of CLI is only compatible with Angular versions 0.0.0 || ^10.0.0-beta || >=10.0.0 <11.0.0,
but Angular version 9.1.1 was found instead.
我更新了 CLI,但它仍然给我同样的错误。
我的 CLI 版本是:
Angular CLI: 10.0.0-next.0
Node: 12.13.0
OS: win32 x64
Angular: 9.1.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
最佳答案
问题
您安装的 CLI 版本不符合您的 Angular 版本的要求,如错误所述:
This version of CLI is only compatible with Angular versions 0.0.0 || ^10.0.0-beta || >=10.0.0 <11.0.0
修复
卸载
@angular/cli
并确保安装 @angular/cli
版本范围内的 9.1.x
,使其符合 Angular 9.1 版本的要求。Angular: 9.1.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
更新 Angular 项目
要在应用程序中卸载并重新安装
@angular/cli
包,请导航到项目的根文件夹并运行以下命令:# uninstall previous version
npm uninstall @angular/cli --save-dev
# install 9.1.x specific version
npm install @angular/cli@~9.1.0 --save-dev
💡 The
--save-dev
parameter will update yourpackage.json
devDependencies
更新全局依赖
如果全局安装了
angular/cli
,则需要在命令末尾添加-g
并省略--save-dev
参数:# uninstall previous globally installed version
npm uninstall @angular/cli -g
# install 9.1.x specific version globally
npm install @angular/cli@~9.1.0 -g
💡 If you are not sure what global version is installed (or if you have installed
@angular/cli
globally) you can run the following command to list your globally installed NPM packages:npm ls -g --depth=0
关于Angular CLI 版本与 Angular 版本不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61218672/