我如何处理在 Angular CLI 中安装对等依赖项? [英] How do I deal with installing peer dependencies in Angular CLI?

查看:35
本文介绍了我如何处理在 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_modules\fsevents):
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 需要一个 peer@angular/core@5.2.1 但没有安装.您必须安装对等方自己依赖.

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.

使用 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 的对等体 ||^4.0.0 但没有安装.您必须安装对等依赖项自己.

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.

如果您使用的是高于 4.0.0 的 Angular 版本,那么您可能没有问题.那就没什么可做的了.如果您使用的是 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 optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3(node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:fsevents@1.1.3 不受支持的平台:需要{"os":"darwin","arch":"any"}(当前:{"os":"win32","arch":"x64"})

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"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 中安装对等依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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