How to avoid duplicate installation of React during package release?
P粉036800074
P粉036800074 2023-09-08 08:41:16
0
1
573

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粉036800074
P粉036800074

reply all(1)
P粉105971514

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:

  • If these dependencies include react that match the version requirements, no other operations are required
  • If no suitable version of react 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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template