Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install npm peer dependencies automatically?

Tags:

node.js

npm

For example, when I install 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.

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?

like image 341
Douglas Ludlow Avatar asked Feb 04 '16 17:02

Douglas Ludlow


People also ask

How do I automatically install npm dependencies?

to install the dependencies automatically , first of all list them manually in package. json file and run the npm install (sometimes sudo npm install ) command.

Do I need to install peer dependencies?

Peer dependencies are almost like normal dependencies, but instead of defining a strong requirement between A and B (i.e the project you're developing and the project it depends on), they're meant to specify a package that your code requires, but doesn't directly require it.

What is a peer dependency in NPM?

Peer Dependencies are used to specify that our package is compatible with a specific version of an npm package. Good examples are Angular and React. To add a Peer Dependency you actually need to manually modify your package.json file. For example, for Angular component library projects, I recommend adding angular/core as a peer dependency.

How to install dependencies as peer-dependencies?

As for now, there is NO WAY, you can install dependencies as peer-dependencies. You have to install then and manually move them to peerDependencies object in package.json The automatic install of peer dependencies was removed with npm v3, this feature is aging added in npm v7.

How to install dependency as a peer dependency in angular?

If You need to install dependency as a peer dependency. To install peer dependency, you actually need to manually modify your package.json file. For example, if you want to install angular's core component library as a peer dependency, This will add a property in the dependencies object. Move the installed package name to peerDependencies key.

Why doesn't NPM@7 support peerdeps?

Another reason is, 'peerDeps' always use a range of semver, and that has to be edit manually not via a npm install command. like react-redux: I think NPM@7 should provide a way to support that, since now it is officially able to process the 'peerDeps' and this feature is part of it.


1 Answers

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:

  • https://blog.npmjs.org/post/110924823920/npm-weekly-5
  • https://github.com/npm/npm/releases/tag/v3.0.0

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

NPM V7

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

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

like image 141
crackmigg Avatar answered Sep 19 '22 18:09

crackmigg