npm prior to v7, will not install plugin's peerDependencies automatically.
In order to properly maintain the plugin, like compile and publish, you will need a way to install these peerDeps in your dev env.
(This may not be an issue to Monorepo)
npm v7 fixed the issue perfectly, so you don't need this topic anymore.
Actually there are 2 ways to handle this issue:
-
Just add these
peerDependenciestodevDependenciesto fit the dev env.
Just these 'devDeps' are not real 'devDeps'. -
Use
preparescript to let NPM to install these 'additional' deps via 3rd party tools, right afternpm install, which is this topic talks about.
"prepare": "npm-install-peers"
About prepare, please see NPM life-cycle-scripts.
Test Design
react-share has a peerDependencies of react
file-loader has a peerDependencies of webpack
Use react-share as peerDependencies and file-loader as dependencies
Check Point
- Can install direct
peerDependencies - Can install
peerDependenciesof thedependencies - Can install
peerDependenciesof thepeerDependencies - Can install
peerDependenciesof thedevDependencies - Install modifies
package.json,package-lock.json
"scripts": {
"prepare": "npm-install-peers"
},
"scripts": {
"prepare": "install-peers"
},
"scripts": {
"prepare": "install-self-peers --npm -- --ignore-scripts"
},
Run: npm install
| npm-install-peers | install-peers-cli | @team-griffin/install-self-peers | |
|---|---|---|---|
| Windows: | ✅(1) | ❌(2) | ❌(3) |
| macOS | ✅(1) | ✅(1) | ❌(3) |
Note:
- All tools just only install direct
peerDependencies, they don't installpeerDependenciesof thedevDependencies,peerDependenciesanddevDependencies. - Known issue, see alexindigo/install-peers-cli#12
- It adds the "peerDependencies" to "dependencies", thus package.json get updated, no good.
So, prefer to use npm-install-peers, and it is also the most popular one.
Go with prepare script, peerDependencies will be re-installed every time you run npm install, which will slow down the install task.
The best choice is to upgrade to npm v7. ^_^