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

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

问题描述

在运行 ng serve 时,我收到有关我的全局 CLI 版本高于本地版本的警告.我没有注意到这个警告有任何问题,但我想知道这两个版本是否应该同步?另外,如果您有全球版本,是否有必要拥有本地版本?

警告:

<块引用>

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

解决方案

要回答其中一个问题,必须同时进行全局和本地安装才能使工具正常工作.

如果您尝试在没有本地安装 CLI(仅限全局安装)的应用程序上运行 ng serve,您将收到以下错误.

<块引用>

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

它还会打印此消息:

请采取以下步骤以避免出现问题:npm install --save-dev @angular/cli@latest"

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

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

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

启动新应用程序需要全局安装.ng new 命令使用 CLI 的全局安装运行.事实上,如果您尝试在现有 CLI 应用程序的文件夹结构中运行 ng new,您会得到这个可爱的错误:

<块引用>

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

其他可以从全局安装运行的命令有 ng helpng get/set--global 选项、<代码>ng 版本、ng docng 补全.

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

根据 CLI GitHub readme,更新您的 CLI必须更新全局和本地包.但是,到目前为止,我已经使用了全局和本地版本不同的 CLI,没有任何问题.如果我遇到与全局和本地 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?

The warning:

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.

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.

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

It will also print this message:

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

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.

Why do we need both the global install, and a local install?

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:

You cannot use the new command inside an Angular CLI project.

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.

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.

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天全站免登陆