connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

Unmet peer dependency 'react-router' despite having 'react-router-dom'

Open lightclient opened this issue 6 years ago • 6 comments

I'm getting a warning during package installations saying the following:

[email protected]" has unmet peer dependency "react-router@^4.3.1"

However, I have react-router-dom as a dependency already which installs react-router. It seems to be working correctly, but it feels like a bug that connected-react-router doesn't realize I have a package which install react-router.

Please advise.

lightclient avatar Jan 26 '19 20:01 lightclient

@supasate Is there any code in connected-react-router that has actual dependencies that aren't in react-router-dom? If not, can we just change the peer dependency to react-router-dom instead of react-router?

imjoshdean-tc avatar Mar 13 '19 19:03 imjoshdean-tc

+1 For this. According to the docs here: https://github.com/ReactTraining/react-router/tree/master/packages/react-router#installation , user would install either react-router-dom or react-router-native, instead of react-router.

govizlora avatar May 02 '19 17:05 govizlora

I'm having the same issue, and I have to admit that I don't really get if the problem is on connected-react-router package.json, or some npm bug, or some misunderstanding mine of how peerDependencies work. Anyway, what sounds really weird to me is that these warnings seem supposed to alert us that we have an incompatible version of the package installed (react-router on this case), which is not true in this case, so why we still seeing that?

So, this is my warning:

warning " > [email protected]" has unmet peer dependency "react-router@^4.3.1 || ^5.0.0".

And since I'm using [email protected] my installed version of react-router is also 5.0.1, which attends perfectly the demands of ^4.3.1 || ^5.0.0

Should I always add react-router as a dependency of my project? Even if I already the right version?

Man, I would be very happy to understand that, haha

diegofelipece avatar Sep 18 '19 09:09 diegofelipece

you can ignore this warning because react-router is installled along with react-router-dom, you can check in your node_modules and you'll find react-router directory

ymeskini avatar Feb 03 '20 14:02 ymeskini

I had the same issue, not just the common unmet dependency error, the error is in the Chrome console and bundle build too.

ateev avatar Feb 17 '20 11:02 ateev

AFAIK, the peer dependencies npm/yarn check only looks if they are specified in the top level of your package.json. It won't be satisfied if there is a private dependency like that of react-router inside react-router-dom. More explanation here: https://stackoverflow.com/questions/26737819/why-use-peer-dependencies-in-npm-for-plugins

It's kind of a flaw in the package managers that they don't give a package author the ability to specify one package or a completely different one. But this problem also came about with how the authors of react-router split up their packaging. Maybe the author(s) of connected-react-router should just switch over the peer-dependency to the one that most people are using (react-router-dom) rather than the safe bet that is react-router?

mdrx-io avatar May 15 '20 03:05 mdrx-io