本文介绍了如何处理在 Angular CLI 中安装对等依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试更新 Angular CLI 和 NPM 时,我发现自己陷入了几乎无穷无尽的错误循环.每次更新时,都会收到 WARN 消息,告诉我安装对等依赖项(见下文),但每次安装依赖项时,都会收到更多 WARN 消息.有没有更好的方法来处理这种情况,还是真的需要几个小时?

I've found myself in an almost endless cycle of errors when trying to update my Angular CLI and NPM. Every time I update, I am met with WARN messages telling me to install peer dependencies (see below), but each time I install a dependency, I am met with more WARN messages. Is there a better way of handling this situation or does it seriously take hours?

npm WARN @angular/animations@5.2.1 requires a peer of @angular/core@5.2.1
but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler-cli@5.1.0 requires a peer of typescript@>=2.4.2
<2.6 but none is installed. You must install peer dependencies yourself.
npm WARN @ng-bootstrap/ng-bootstrap@1.0.0-beta.6 requires a peer of
@angular/core@^4.0.3 but none is installed. You must install peer
dependencies yourself.
npm WARN @ng-bootstrap/ng-bootstrap@1.0.0-beta.6 requires a peer of
@angular/common@^4.0.3 but none is installed. You must install peer
dependencies yourself.
npm WARN @ng-bootstrap/ng-bootstrap@1.0.0-beta.6 requires a peer of
@angular/forms@^4.0.3 but none is installed. You must install peer
dependencies yourself.
npm WARN @schematics/angular@0.1.17 requires a peer of @angular-
devkit/core@0.0.29 but none is installed. You must install peer dependencies
yourself.
npm WARN @schematics/angular@0.1.17 requires a peer of @angular-
devkit/schematics@0.0.52 but none is installed. You must install peer
dependencies yourself.
npm WARN @schematics/schematics@0.0.11 requires a peer of @angular-
devkit/core@0.0.22 but none is installed. You must install peer dependencies
yourself.
npm WARN angular2-notifications@0.7.4 requires a peer of
@angular/core@^4.0.1 but none is installed. You must install peer
dependencies yourself.
npm WARN angular2-notifications@0.7.4 requires a peer of
@angular/common@^4.0.1 but none is installed. You must install peer
dependencies yourself.
npm WARN angular2-notifications@0.7.4 requires a peer of @angular/platform-
browser@^4.0.0 but none is installed. You must install peer dependencies
yourself.
npm WARN angular2-notifications@0.7.4 requires a peer of
@angular/animations@^4.0.1 but none is installed. You must install peer
dependencies yourself.
npm WARN bootstrap@4.0.0-beta.2 requires a peer of jquery@1.9.1 - 3 but none
is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.0.0-beta.2 requires a peer of popper.js@^1.12.3 but
none is installed. You must install peer dependencies yourself.
npm WARN ng2-toasty@4.0.3 requires a peer of @angular/core@^2.4.7 || ^4.0.0
but none is installed. You must install peer dependencies yourself.
npm WARN ngx-carousel@1.3.5 requires a peer of @angular/core@^2.4.0 ||
^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-carousel@1.3.5 requires a peer of @angular/common@^2.4.0 ||
^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsickle@0.25.5 requires a peer of typescript@>=2.4.2 <2.6 but none
is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3
(node_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for
fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current:
{"os":"win32","arch":"x64"})

我知道我一定做错了什么,但我是 Angular 新手.

I know I must be doing something wrong, but I'm new to Angular.

推荐答案

通常可以忽略对等依赖警告.唯一需要采取措施的情况是对等依赖项完全丢失,或者对等依赖项的版本高于您安装的版本.

Peer dependency warnings, more often than not, can be ignored. The only time you will want to take action is if the peer dependency is missing entirely, or if the version of a peer dependency is higher than the version you have installed.

我们以这个警告为例:

npm WARN @angular/animations@5.2.1 需要@angular/core@5.2.1 但没有安装.您必须安装对等自己依赖.

使用 Angular,您希望您使用的版本在所有包中保持一致.如果有任何不兼容的版本,请更改 package.json 中的版本,然后运行 ​​npm install 以使它们全部同步.我倾向于将我的 Angular 版本保持在最新版本,但您需要确保您的版本与您需要的任何 Angular 版本一致(可能不是最新版本).

With Angular, you would like the versions you are using to be consistent across all packages. If there are any incompatible versions, change the versions in your package.json, and run npm install so they are all synced up. I tend to keep my versions for Angular at the latest version, but you will need to make sure your versions are consistent for whatever version of Angular you require (which may not be the most recent).

在这样的情况下:

npm WARN ngx-carousel@1.3.5 需要 @angular/core@^2.4.0 的 peer ||^4.0.0 但没有安装.您必须安装对等依赖项自己.

如果您使用的 Angular 版本高于 4.0.0,那么您可能不会遇到任何问题.那就不用管这个了.如果您使用的是 2.4.0 以下的 Angular 版本,则需要升级您的版本.更新 package.json,然后运行 ​​npm install,或运行 npm install 以获得您需要的特定版本.像这样:

If you are working with a version of Angular that is higher than 4.0.0, then you will likely have no issues. Nothing to do about this one then. If you are using an Angular version under 2.4.0, then you need to bring your version up. Update the package.json, and run npm install, or run npm install for the specific version you need. Like this:

npm install @angular/core@5.2.3 --save

如果您运行的是 npm 5.0.0 或更高版本,您可以省略 --save,该版本将包保存在 package.json 的依赖项部分自动.

You can leave out the --save if you are running npm 5.0.0 or higher, that version saves the package in the dependencies section of the package.json automatically.

在这种情况下:

npm WARN 可选跳过可选依赖:fsevents@1.1.3(node_modulesfsevents): npm WARN notsup 跳过可选依赖:fsevents@1.1.3 不受支持的平台:需要{"os":"darwin","arch":"any"}(当前:{"os":"win32","arch":"x64"})

您正在运行 Windows,fsevent 需要 OSX.可以忽略此警告.

You are running Windows, and fsevent requires OSX. This warning can be ignored.

希望这对您有所帮助,并享受学习 Angular 的乐趣!

Hope this helps, and have fun learning Angular!

这篇关于如何处理在 Angular CLI 中安装对等依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 05:05