全局Angular CLI版本大于本地版本

本文翻译自:Global Angular CLI version greater than local version

When running ng serve I get this warning about my global CLI version being greater than my local version. 运行ng serve此警告,提示我的全局CLI版本大于本地版本。 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). 您的全局Angular CLI版本(1.1.1)大于本地版本(1.0.6)。 The local Angular CLI version is used. 使用本地Angular CLI版本。


#1楼

参考:https://stackoom.com/question/30pBC/全局Angular-CLI版本大于本地版本


#2楼

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. 如果您尝试在没有本地安装CLI的应用程序上运行ng serve (仅全局安装),则会收到以下错误。

You have to be inside an Angular CLI project in order to use the serve command. 您必须在Angular CLI项目中才能使用serve命令。

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. 运行该npm命令以在本地更新CLI,并避免收到警告。

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 command is run using the global installation of the CLI. ng new 命令是使用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: 实际上,如果您尝试在现有CLI应用程序的文件夹结构中运行ng new时,将得到以下可爱错误:

You cannot use the new command inside an Angular CLI project. 您不能在Angular CLI项目中使用new命令。

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 . 这可以从全局来运行其他命令安装在ng helpng get/set--global选项, ng versionng doc ,并ng completion

The local install of the CLI is used after an application has been built. 在构建应用程序之后,将使用CLI的本地安装。 This way, when new versions of the CLI are available, you can update your global install, and not affect the local install. 这样,当新版本的CLI可用时,您可以更新全局安装,而不会影响本地安装。 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. 大多数ng命令仅适用于本地版本,例如lintbuildserve等。

According to the CLI GitHub readme , to update the CLI you must update the global and local package. 根据CLI GitHub 自述文件 ,要更新CLI,必须更新全局和本地软件包。 However, I have used the CLI where the global and local version vary without any trouble so far. 但是,到目前为止,我使用的CLI的全局和本地版本有所不同。 If I ever run across an error related to having the global and local CLI versions out of sync, I will post that here. 如果我遇到与使全局和本地CLI版本不同步有关的错误,我将在此处发布。


#3楼

This is how I solved the issue. 这就是我解决问题的方式。

Copy and run these commands 复制并运行这些命令

ng --version
npm install --save-dev @angular/cli@latest
ng --version

#4楼

This works for me: it will update local version to latest 这对我有用:它将本地版本更新为最新版本

npm uninstall --save-dev angular-cli
npm install --save-dev @angular/cli@latest
npm install

to verify version 验证版本

  ng --version

#5楼

Run the following Command: npm install --save-dev @angular/cli@latest 运行以下命令: npm install --save-dev @angular/cli@latest

After running the above command the console might popup the below message 运行上述命令后,控制台可能会弹出以下消息

The Angular CLI configuration format has been changed, and your existing configuration can be updated automatically by running the following command: ng update @angular/cli Angular CLI配置格式已更改,可以通过运行以下命令来自动更新现有配置:ng update @ angular / cli


#6楼

npm uninstall --save-dev angular-cli
npm install --save-dev @angular/cli@latest

Your existing configuration can be updated automatically by running the following command: 您可以通过运行以下命令来自动更新现有配置:

ng update @angular/cli

or: 要么:

npm install

你可能感兴趣的:(全局Angular CLI版本大于本地版本)