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?
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.
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.
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"
}
What about:
"peerDependencies": {
"react": "^15.0.0 || ^16.0.0",
"react-dom": "^15.0.0 || ^16.0.0"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With