Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save peer dependencies in npm with a command

Is there a way to achieve that using npm ? Currently I do this manually, would be nice to use similar approach as with npm install --save

I found some old discussion and commits but it seems it didn't make it:

https://github.com/npm/npm/pull/3994

like image 486
Piotr Avatar asked Jan 16 '19 13:01

Piotr


People also ask

Does npm automatically install peer dependencies?

Current Behavior When running npm install , it does not install the peer dependencies automatically even if they are in the package-lock. json file. Instead it modifies the package-lock.

How do I add a dependency in npm?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.

How do peer dependencies work npm?

A peer dependency specifies that our package is compatible with a particular version of an npm package. If a package doesn't already exist in the node_modules directory, then it is automatically added. As you install a package, npm will automatically install the dev dependencies.

What is -- Save flag in npm install?

If you are using a recent version of npm save yourself from unnecessary typing and use npm install [Package Name] instead of npm install [Package Name] --save by default it will add the installed package to the dependency list in the package. json file.


1 Answers

As far as I can tell, you can't. Just install it as a regular dependency (production or otherwise, just like the package requiring the peer dependency is installed as).

Even if you manually add the entry to peerDependencies an npm audit is going to fail to recognize the package and tell you to install it.

This kind of stinks, I'm a big fan of the separation of concerns, and keeping a list of modules that only exist so they can be absorbed by other modules is crummy.

But, it is what it is and so long as you leverage the npm commands afforded to you, I guess it's manageable.

like image 72
Jimmay Avatar answered Sep 24 '22 00:09

Jimmay