全局Angular CLI版本大于本地版本 [英] Global Angular CLI version greater than local version

查看:257
本文介绍了全局Angular CLI版本大于本地版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行ng serve时,出现此警告,提示我的全局CLI版本大于本地版本.我没有从该警告中注意到任何问题,但是我想知道两个版本是否应该同步?另外,如果您具有全局版本,是否必须具有本地版本?

When running ng serve I get this warning about my global CLI version being greater than my local version. I don't notice any issues from this warning, but I was wondering if the two versions should be in sync? Also, Is it necessary to have a local version if you have a global version?

警告:

您的全局Angular CLI版本(1.1.1)大于本地版本(1.0.6).使用本地Angular CLI版本.

Your global Angular CLI version (1.1.1) is greater than your local version (1.0.6). The local Angular CLI version is used.

推荐答案

要回答其中一个问题,必须同时在全局和本地安装该工具.

To answer one of the questions, it is necessary to have both a global and local install for the tools to work.

如果尝试在没有本地安装CLI的应用程序上运行ng serve(仅全局安装),则会出现以下错误.

If you try to run ng serve on an application without the local install of the CLI (global install only), you will get the following error.

您必须在Angular CLI项目中才能使用serve命令.

You have to be inside an Angular CLI project in order to use the serve command.

它还将打印此消息:

Please take the following steps to avoid issues:
"npm install --save-dev @angular/cli@latest"

运行该npm命令以在本地更新CLI,并避免收到警告.

Run that npm command to update the CLI locally, and avoid the warning that you are getting.

其他问题:看来他们没有同步,但最好是避免使用该工具的任何异常行为,或与该代码的任何不一致.工具生成.

Other question: It looks like they do not have to be in sync, but it's probably best that they are in order to avoid any unusual behavior with the tool, or any inconsistencies with the code the tool generates.

为什么我们既需要全局安装又需要本地安装?

需要全局安装才能启动新的应用程序. ng new <app-name>命令是使用CLI的全局安装运行的.实际上,如果您尝试在现有CLI应用程序的文件夹结构中运行ng new时,会得到以下可爱错误:

The global install is needed to start a new application. The ng new <app-name> command is run using the global installation of the CLI. In fact, if you try to run ng new while inside the folder structure of an existing CLI application, you get this lovely error:

您不能在Angular CLI项目中使用new命令.

可以从全局安装运行的其他命令是ng help,带有--global选项的ng get/setng versionng doc

Other commands that can be run from the global install are ng help, ng get/set with the --global option, ng version, ng doc, and ng completion.

在构建应用程序之后,将使用CLI的本地安装.这样,当新版本的CLI可用时,您可以更新全局安装,而不会影响本地安装.这有利于项目的稳定性.大多数ng命令仅适用于本地版本,例如lintbuildserve等.

The local install of the CLI is used after an application has been built. This way, when new versions of the CLI are available, you can update your global install, and not affect the local install. This is good for the stability of a project. Most ng commands only make sense with the local version, like lint, build and serve, etc.

根据CLI GitHub 自述文件,以更新您的CLI必须更新全局和本地程序包.但是,到目前为止,我使用的CLI的全局和本地版本有所不同.如果遇到与使全局和本地CLI版本不同步有关的错误,我将在此处发布.

According to the CLI GitHub readme, to update the CLI you must update the global and local package. However, I have used the CLI where the global and local version vary without any trouble so far. If I ever run across an error related to having the global and local CLI versions out of sync, I will post that here.

这篇关于全局Angular CLI版本大于本地版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆