且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将Angular CLI升级到最新版本

更新时间:2023-02-22 22:39:02

阅读了GitHub存储库上报告的一些问题之后,我找到了解决方案.

After reading some issues reported on the GitHub repository, I found the solution.

为了更新系统中全局安装的angular-cli软件包,您需要运行:

In order to update the angular-cli package installed globally in your system, you need to run:

npm uninstall -g @angular-cli
npm install -g @angular/cli@latest

根据您的系统,您可能需要在上述命令前面加上sudo.

Depending on your system, you may need to prefix the above commands with sudo.

此外,您很可能还希望更新本地项目版本,因为在项目目录中将其选择的优先级高于全局目录的优先级:

Also, most likely you want to also update your local project version, because inside your project directory it will be selected with higher priority than the global one:

rm -rf node_modules
npm uninstall --save-dev @angular-cli
npm install --save-dev @angular/cli@latest
npm install

感谢 grizzm0 GitHub .

更新CLI后,您可能也想更新Angular版本.

After updating your CLI, you probably want to update your Angular version too.

注意:如果要从较早版本更新到Angular CLI 6+,则可能需要阅读

Note: if you are updating to Angular CLI 6+ from an older version, you might need to read this.

编辑:此外,如果您仍使用cli的1.x版本,则需要将angular-cli.json转换为angular.json,可以使用以下命令进行操作:

Edit: In addition, if you were still on a 1.x version of the cli, you need to convert your angular-cli.json to angular.json, which you can do with the following command:

ng update @angular/cli --from=1.7.4 --migrate-only

(有关更多详细信息,请参见)

(check this for more details).