8

I have seen similar questions on stackoverflow regarding npm peerDependencies warnings - but none address best practices for actually installing the dependencies. i.e., are we now supposed to save them along with our dependencies and devDependencies? If that's the case, what's the purpose of the peerDependencies in package.json?

After installing some other npm packages, I'm getting a slew of warnings along the lines of:

npm WARN slate-prop-types@0.4.32 requires a peer of slate@>=0.32.0 but none is installed. You must install peer dependencies yourself.

So what I did is set a peerDependencies object in package.json, and include what it's asking for:

...
"peerDependencies": {
  "slate": "0.32.0"
},
...

rerun npm i, but the warning still persists.

The warning only goes away when I include the peerDependency within devDependencies or dependencies, which I don't really want to do since it muddies what packages my project directly depends on.

What's the right way to go about this?

jchi2241
  • 2,032
  • 1
  • 25
  • 49
  • Can you try `npm install --save slate@0.32.0` – Isaac Jun 22 '18 at 01:57
  • 1
    @Isaac That will work, but as I mentioned it will save it to `dependencies` which I don't prefer. Is this best practice for dealing with peerDependencies? – jchi2241 Jun 22 '18 at 02:04
  • Possible duplicate of [How to install npm peer dependencies automatically?](https://stackoverflow.com/questions/35207380/how-to-install-npm-peer-dependencies-automatically) – Raptor Jun 22 '18 at 02:08
  • See the duplicate: *The automatic install of peer dependencies was explicitly removed with npm 3, as it cause more problems than it tried to solve* – Raptor Jun 22 '18 at 02:09
  • 1
    @Raptor I understand that it has been removed in npm 3 - but what's the best practice for installing them manually? If the peerDependencies object isn't doing anything - what is it's purpose? – jchi2241 Jun 22 '18 at 02:13
  • Please read "Peer dependencies" section: https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/ – Raptor Jun 22 '18 at 02:16
  • 5
    @Raptor I have read this article - but again it doesn't state HOW to actually go about installing peer dependencies. – jchi2241 Jun 22 '18 at 15:38
  • Peer dependencies may not be required. As suggested by Issac, you can install the peer dependencies manually, only when you're told to install the software. – Raptor Jun 25 '18 at 02:43
  • Having a peerDependencies in your package.json IS about the peer dependencies your package require. Most of the time if you are not developing a package to be installed by others, you don't need this. The warning you are getting is about a package you are depending on requires a peer dependency. In your case `slate-prop-types` requires `slate`; you need to install it manually. – dereli Feb 22 '19 at 10:55
  • 1
    Oh guys, comon. Just answer the question - HOW TO INSTALL PEER DEPENDENCIES MANUALLY? Is it about running `npm install slate@0.32.0 --no-save`? If so, next run of `npm install` will remove all of the peer dependencies. What if I have a plugin project, and I'm testing it w/o a host app? – Rustem Zinnatullin Apr 03 '20 at 06:09
  • you can reference to this answer https://stackoverflow.com/a/61114706/8175165 – Wayne Mao Aug 26 '21 at 14:07

1 Answers1

0

When doing npm-install PeerDependencies not installed. Peer Dependencies are listed in the package.json file in the peerDependencies object. They are automatilcally can install using npm, npm install --save-dev --ignore-scripts install-peers