node.js 如何自动安装 npm peer 依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35207380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install npm peer dependencies automatically?
提问by Douglas Ludlow
For example, when I install Angular2:
例如,当我安装 Angular2 时:
npm install --save angular2
[email protected] /Users/doug/Projects/dougludlow/temp
├── [email protected]
├── UNMET PEER DEPENDENCY es6-promise@^3.0.2
├── UNMET PEER DEPENDENCY es6-shim@^0.33.3
├── UNMET PEER DEPENDENCY [email protected]
├── UNMET PEER DEPENDENCY [email protected]
└── UNMET PEER DEPENDENCY [email protected]
npm WARN [email protected] requires a peer of es6-promise@^3.0.2 but none was installed.
npm WARN [email protected] requires a peer of es6-shim@^0.33.3 but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
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.
是否有一个魔术标志可以传递给 npm 来安装对等依赖项?我一直找不到...手动复制和粘贴对等依赖项并确保我拥有正确的版本很乏味。
In other words, I'd rather not have to do:
换句话说,我宁愿不必这样做:
npm install --save [email protected] es6-promise@^3.0.2 es6-shim@^0.33.3 [email protected] [email protected] [email protected]
What is the better way?
什么是更好的方法?
采纳答案by migg
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 3 自动安装它们。
回答by MrLehiste
I solved it by rewriting package.json with the exact values warnings were about:
我通过使用警告的确切值重写 package.json 解决了它:
npm WARN [email protected] requires a peer of es6-shim@^0.33.3 but none was installed.
package.json: "es6-shim": "^0.33.3",
package.json: "es6-shim": "^0.33.3",
npm WARN [email protected] requires a peer of [email protected]
package.json: "reflect-metadata": "0.1.2",
package.json: "reflect-metadata": "0.1.2",
Delete node_modules directory
npm install
回答by zoomlar
Cheat code helpful in this scenario and some others...
作弊代码在这种情况下和其他一些情况下很有帮助......
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/platform-b[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected] >
├── UNMET PEER DEPENDENCY @angular/platform-b[email protected] >
- copy & pasteyour error into your code editor.
- Highlight an unwantedpart with your curser. In this case '├── UNMET PEER DEPENDENCY'
- Press command + da bunch of times.
- Press delete twice. (Press space if you accidentally highlighted '├── UNMET PEER DEPENDENCY '.)
- Press up once. Add 'npm install'
- Press down once. Add '--save
- Copy your stuff back into the cli and run
- 将您的错误复制并粘贴到您的代码编辑器中。
- 用光标突出显示不需要的部分。在这种情况下 '├── UNMET PEER DEPENDENCY'
- 多次按command + d。
- 按两次删除。(如果您不小心突出显示了 '├── UNMET PEER DEPENDENCY ',请按空格键。)
- 按一次。添加'npm安装'
- 按下一次。添加'--保存
- 将你的东西复制回 cli 并运行
npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] --save
npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] .2 @angular/platform-b[email protected] @angular/platform-b[email protected] --save
回答by deepelement
The project npm-install-peerswill detect peers and install them.
该项目npm-install-peers将检测对等点并安装它们。
As of v1.0.1it doesn't support writing back to the package.jsonautomatically, which would essentially solve our need here.
由于v1.0.1它不支持package.json自动回写,这基本上可以解决我们的需求。
Please add your support to issue in flight: https://github.com/spatie/npm-install-peers/issues/4
请添加您对飞行中问题的支持:https: //github.com/spatie/npm-install-peers/issues/4
回答by joshweir
I experienced these errors when I was developing an npm package that had peerDependencies. I had to ensure that any peerDependencieswere also listed as devDependencies. The project would not automatically use the globally installed packages.
我在开发具有peerDependencies. 我必须确保 anypeerDependencies也被列为devDependencies. 该项目不会自动使用全局安装的包。
回答by Carlos
Install yarn an then run
安装纱线然后运行
yarn global add install-peerdeps
纱线全局添加安装peerdeps
回答by Ivan Ferrer
Execute this: npm install-test
执行这个: npm install-test

