Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make your NPM package support multiple versions of peer depedency

I have a package on NPM that is using React version 15 as peer dependency. However, I want it to stop from throwing warnings for users that upgraded their React version. How do I make package support both version 15 and 16?

"peerDependencies": {
    "react-dom": "^15.0.0"
  },

which is the most convenient way to deal with these?

Is "*15.0.0" good enough?

like image 880
Kunok Avatar asked Nov 15 '17 14:11

Kunok


People also ask

Can you have multiple versions of npm installed?

The good news is that you can have it done directly via NPM! What can be done in this case is an idea called "package alias". So you can have multiple versions of the same package running in your app and you can work on the upgrades mitigating possible issues.

Will npm install peer dependencies?

UPDATE: npm versions 1, 2, and 7 will automatically install peerDependencies if they are not explicitly depended upon higher in the dependency tree. For npm versions 3 through 6, you will receive a warning that the peerDependency is not installed instead.


2 Answers

Just checked some other packages on GitHub how they do it.

Using * didn't work out for me and therefore seems like bad practice anyway.

Better solution:

  "peerDependencies": {
    "react": ">=0.14.0 <= 16",
    "react-dom": ">=0.14.0 <= 16"
  }
like image 133
Kunok Avatar answered Oct 21 '22 10:10

Kunok


What about:

"peerDependencies": {
  "react": "^15.0.0 || ^16.0.0",
  "react-dom": "^15.0.0 || ^16.0.0"
}
like image 36
Andrea Carraro Avatar answered Oct 21 '22 11:10

Andrea Carraro