I'm building a small, lightweight toolbox for Angular which I intend to publish as a package.
My package depends on Rxjs version Y.
Angular depends on Rxjs version Z.
Because this is recent, for now, versions Y & Z are the same, but as Angular releases major versions every 6 months, it may not remain that way for long.
Rxjs' footprint in my library is very minimal and is not likely to change any time soon. I'd like to be able to ensure that in the case that I don't update my library for a while, using it in an Angular project isn't going to result in two different versions of rxjs being included in the bundle.
Is there any way to pin the dependency version of my library to whichever version another package uses?
CodePudding user response:
You can use the peerDependencies
property in your package.json
file.
Essentially, npm won’t install it, you expect for it to already be installed.Peer dependencies are dependencies that are "owned" by your consumers. They are installed by your consumers, and you expect them to be available at runtime.
{
"name": "my-library",
"version": "1.0.0",
"peerDependencies": {
"rxjs": "^6.0.0"
}
}