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

时间:2018-02-05 15:32:55

标签: angular dependencies angular-cli npm-install

在尝试更新我的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"})

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

5 个答案:

答案 0 :(得分:45)

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

让我们以此警告为例:

  

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

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

在这种情况下:

  

npm WARN可选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”})

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

希望这会有所帮助,并乐于学习Angular!

答案 1 :(得分:0)

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

ng update @angular/cli @angular/core --force

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

答案 2 :(得分:0)

我发现在您的Angular项目所在的同一目录中运行npm install命令 可以消除这些警告。我不知道为什么。

具体来说,我正在尝试使用ng2-completer

$ npm install ng2-completer --save
npm WARN saveError ENOENT: no such file or directory, open 'C:\Work\foo\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Work\foo\package.json'
npm WARN ng2-completer@3.0.3 requires a peer of @angular/common@>= 6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng2-completer@3.0.3 requires a peer of @angular/core@>= 6.0.0 but noneis installed. You must install peer dependencies yourself.
npm WARN ng2-completer@3.0.3 requires a peer of @angular/forms@>= 6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN foo No description
npm WARN foo No repository field.
npm WARN foo No README data
npm WARN foo No license field.

我无法编译。 当我再次尝试时,这一次在foo / foo_app中的Angular项目目录中,它运行良好。

cd foo/foo_app
$ npm install ng2-completer --save

答案 3 :(得分:0)

NPM软件包库在package.json文件中有一个名为peerDependencies的部分。例如;内置于Angular 8中的库通常会将Angular 8列为依赖项。对于运行版本低于8的任何人来说,这是一个真正的依赖关系。但是对于运行版本8、9或10的任何人,是否应该关注任何问题都令人怀疑。

我一直安全地忽略了Angular Updates上的这些消息,但是我们再次有了单元测试和赛普拉斯测试!

答案 4 :(得分:0)

更新您的角度(全局):

  • 通过更新:
<块引用>

ng 更新 @angular/cli @angular/core

  • 或删除 angular 并重新安装:
<块引用>

npm uninstall -g @angular/cli
npm install -g @angular/cli

之后,如果您想使用旧的 Angular 项目(本地):

  • 使用 npm list 测试某些依赖项是否已更改并收到此错误:
<块引用>

npm 错误! peer dep 丢失:mydependencie,某些组件需要

这意味着您必须更新您的项目:

  • 然后您可以创建一个新项目,粘贴您的代码并重新安装所有依赖项
  • 或者安装 npm list 所需的所有依赖项:
<块引用>

npm install mydependencie