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


77

尝试更新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的新手。

Answers:


80

对等依赖性警告通常可以忽略。您唯一要采取的措施是完全失去对等依赖项,或者对等依赖项的版本高于已安装的版本。

让我们以以下警告为例:

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

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

在这个情况下:

npm警告可选跳过功能:fsevents@1.1.3(node_modules \ fsevents):npm警告不支持跳过可选功能:fsevents@1.1.3不受支持的平台:想要的{“ os”:“ darwin”,“ arch”:“任何“}(当前:{” os“:” win32“,” arch“:” x64“})

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

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


谢谢!我应该更新package.json中“ dependencies”和“ devDependencies”中的版本,还是创建一个“ peerDependencies”并添加这些版本?
汤米

我对不必担心的评论devDependencies是不对的。您也将要在该部分中更新版本号。该部分中的Angular软件包应与该dependencies部分中的软件包具有相同的版本。更改版本可能还需要做一些事情。抱歉给您带来任何混乱!
理查兹

似乎是计算机的一项任务,所有信息都在package.json中,而且我的操作系统很明显,学习这些信息并不有趣。有一天,人们说“我们的祖先遭受了很多苦难,使我们明白了这一点”
mkb

@ R.Richards写道:“如果使用的Angular版本高于4.0.0,则可能没有问题。” 分析仪能否检测到高于4.0.0的Angular?如果是,那么为什么显示此警告?
chrisinmtown,

对不起,很抱歉,但是我不明白为什么您会收到类似`@ angular / core @ ^ 2.4.0 ||的警告。^ 4.0.0,但如果您使用的是高于4.0.0的Angular版本,则未安装任何内容...仅仅是因为该版本已关闭?
Yann

3

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

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

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


4
如果能快速解释一下它的作用以及为什么它可以帮助您解决OP提出的问题,我会发现此答案会更有帮助
-JTech,

@JTech我已经更新了答案,感谢您的反馈。
Wojtek Dmyszewicz

使用clientapp文件夹内的node js命令提示符,它正在工作,非常感谢
hosam hemaily 19'Aug

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

0

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

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

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.