I've been developing with React for a long time, but only recently tried publishing packages.
One of the dependencies of a package I'm developing is causing problems with React installations where there's a conflict between the package and the project it's being installed into. (The package is react-query)
How should I handle this situation?
Ideally I would like the two versions to be consistent, as React 17.x and React 18.x have weird type changes that cause problems when they are used together. But honestly, I'm completely lost.
Searching doesn't seem to turn up anything I can use.
P粉1059715142023-09-09 07:17:07
You should specify react
as peer dependency in your lib package.json file:
"peerDependencies": { "react": ">= 17" }
When encountering a peer dependency, npm will check the dependencies of the project using your lib:
react
that match the version requirements, no other operations are requiredreact
is found, npm
will install the latest matching version In older versions of npm
the behavior may be different and only warnings will be printed in the console during npm install
.