如何在Angular CLI中处理安装对等依赖项?

tom*_*mmy 55 dependencies npm-install angular-cli angular

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

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"})
Run Code Online (Sandbox Code Playgroud)

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

R. *_*rds 64

对等依赖性警告通常可以忽略.您唯一想要采取行动的时间是完全丢失对等依赖关系,或者对等关系的版本是否高于您安装的版本.

让我们以此警告为例:

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

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

在这种情况下:

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

如果您使用的是Angular版本高于4.0.0,那么您可能没有任何问题.那么这个没什么关系的.如果您使用2.4.0下的Angular版本,则需要启动版本.更新package.json,然后运行npm install或运行npm install所需的特定版本.像这样:

npm install @angular/core@5.2.3 --save
Run Code Online (Sandbox Code Playgroud)

--save如果您运行的是npm 5.0.0或更高版本,则可以省略该版本,该版本会自动将软件包保存在package.json的dependencies部分中.

在这种情况下:

npm WARN可选SKIPPING OPTIONAL DEPENDENCY:fsevents@1.1.3(node_modules\fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:不支持的fsevents@1.1.3平台:want {"os":"darwin","arch":"any "}(当前:{"os":"win32","arch":"x64"})

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

希望这有助于学习Angular并获得乐趣!


Woj*_*icz 5

更新依赖项时,您可以通过在 Angular cli 中使用 --force 标志来忽略对等依赖项警告。

ng update @angular/cli @angular/core --force
Run Code Online (Sandbox Code Playgroud)

有关选项的完整列表,请查看文档: https: //angular.io/cli/update

  • 如果这个答案包含对其作用的快速解释以及为什么它可以帮助您解决OP提出的问题,我会发现这个答案更有帮助 (7认同)