如何自动安装 npm peer 依赖项? [英] How to install npm peer dependencies automatically?

查看:181
本文介绍了如何自动安装 npm peer 依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当我安装 Angular2 时:

For example, when I install Angular2:

npm install --save angular2
temp@1.0.0 /Users/doug/Projects/dougludlow/temp
├── angular2@2.0.0-beta.3 
├── UNMET PEER DEPENDENCY es6-promise@^3.0.2
├── UNMET PEER DEPENDENCY es6-shim@^0.33.3
├── UNMET PEER DEPENDENCY reflect-metadata@0.1.2
├── UNMET PEER DEPENDENCY rxjs@5.0.0-beta.0
└── UNMET PEER DEPENDENCY zone.js@0.5.11

npm WARN angular2@2.0.0-beta.3 requires a peer of es6-promise@^3.0.2 but none was installed.
npm WARN angular2@2.0.0-beta.3 requires a peer of es6-shim@^0.33.3 but none was installed.
npm WARN angular2@2.0.0-beta.3 requires a peer of reflect-metadata@0.1.2 but none was installed.
npm WARN angular2@2.0.0-beta.3 requires a peer of rxjs@5.0.0-beta.0 but none was installed.
npm WARN angular2@2.0.0-beta.3 requires a peer of zone.js@0.5.11 but none was installed.

是否有一个魔法标志可以传递给 npm 来安装对等依赖项?我一直找不到...手动复制和粘贴对等依赖项并确保我有正确的版本很乏味.

Is there a magic flag that I can pass to npm that will install the peer dependencies as well? I haven't been able to find one... It's tedious to manually copy and paste the peer dependencies and make sure I have the correct versions.

换句话说,我宁愿不必这样做:

In other words, I'd rather not have to do:

npm install --save angular2@2.0.0-beta.3 es6-promise@^3.0.2 es6-shim@^0.33.3 reflect-metadata@0.1.2 rxjs@5.0.0-beta.0 zone.js@0.5.11

什么是更好的方法?

推荐答案

在 npm 3 中明确删除了对等依赖项的自动安装,因为它导致的问题比它试图解决的问题要多.您可以在此处阅读,例如:

The automatic install of peer dependencies was explicitly removed with npm 3, as it cause more problems than it tried to solve. You can read about it here for example:

所以不,由于给出的原因,您不能使用 npm 3 自动安装它们.

So no, for the reasons given, you cannot install them automatically with npm 3 upwards.

NPM V7

NPM v7 重新引入了自动 peerDependencies 安装.他们进行了一些更改以修复旧问题,因为跨多个依赖项的版本兼容性.您可以在此处查看讨论公告这里

NPM v7 has reintroduced the automatic peerDependencies installation. They had made some changes to fix old problems as version compatibility across multiple dependants. You can see the discussion here and the announcement here

现在在 V7 中,就像在 V3 之前的版本中一样,您只需要执行一个 npm i 并且应该自动安装所有 peerDependences.

Now in V7, as in versions before V3, you only need to do an npm i and all peerDependences should be automatically installed.

这篇关于如何自动安装 npm peer 依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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