How to install npm peer dependencies automatically?

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. 

Is there a magic flag that I can pass to npm that will also set peer dependencies? I could not find it ... It was hard for me to manually copy and paste peer dependencies and make sure that I have the correct versions.

In other words, I would rather not 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 

What is the best way?

+163
Feb 04 '16 at 17:15
source share
4 answers

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

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

+118
Feb 04 '16 at 17:43
source share

I decided to rewrite it package.json with exact values ​​warnings:

 npm WARN angular2@2.0.0-beta.3 requires a peer of es6-shim@^0.33.3 but none was installed. 

package.json: "es6-shim": "^ 0.33.3",

 npm WARN angular2@2.0.0-beta.3 requires a peer of reflect-metadata@0.1.2 

package.json: "reflect-metadata": "0.1.2",

 Delete node_modules directory npm install 
+25
Feb 29 '16 at 0:29
source share

The npm-install-peers project will detect peers and install them.

Starting with v1.0.1 it does not support automatic v1.0.1 in package.json , which, in essence, would solve our problem.

Please add your support for in-flight release: https://github.com/spatie/npm-install-peers/issues/4

+13
Oct 18 '16 at 13:43
source share

The cheat code is useful in this scenario and some other ...

M── UNMET PEER DEPENDENCE @ angular / common @ 4.0.2

M── UNMET PEER DEPENDENCE @ angular / compiler @ 4.0.2

M── UNMET PEER DEPENDENCE @ angular / compiler-cli @ 4.0.2

M── UNMET PEER DEPENDENCE @ angular / core @ 4.0.2

M── UNMET PEER DEPENDENCE @ angular / forms @ 4.0.2

M── UNMET PEER DEPENDENCE @ angular / http @ 4.0.2

M── UNMET PEER DEPENDENCE @ angular / platform-browser @ 4.0.2

UN── UNMET PEER DEPENDENCE @ angular / platform-browser-dynamic @ 4.0.2>

  1. copy and paste the error into the code editor.
  2. Highlight the unwanted part with your curser. In this case, "INDEPENDENT INDEPENDENCE"
  3. Press the + d command several times.
  4. Click delete twice . (Press the spacebar if you accidentally highlighted 'M── INDEPENDENT ATTITUDE AT A FEAST'.)
  5. Click once. Add 'npm install'
  6. Click once. Add '--save
  7. Copy your stuff back to Cli and run

npm install @ angular / common @ 4.0.2 @ angular / compiler @ 4.0.2 @ angular / compiler-cli @ 4.0.2 @ angular / core @ 4.0.2 @ angular / forms @ 4.0.2 @ angular / http @ 4.0 .2 @ angular / platform-browser @ 4.0.2 @ angular / platform-browser-dynamic @ 4.0.2 --save

+8
Jun 27 '18 at 13:18
source share



All Articles