5

I have encountered a problem when trying to install connected-react-router in my test project on React 18: npm installation fails with an error:

npm ERR! Found: react@18.1.0

npm ERR! node_modules/react

npm ERR! react@"^18.1.0" from the root project

npm ERR! npm ERR! Could not resolve dependency

npm ERR! peer react@"^16.4.0 || ^17.0.0" from connected-react-router@6.9.2 or similar packages with

I found information in the repository of connected-react-router that:

v6.0.0 requires React v16.4.0 and React Redux v6.0 / v7.0.

So, I have questions: 1) is connected-react-router maintained? The date of last commits is 7 months ago; 2) are there any similar packages to connect router in React 18 project? Or any inbuilt functionality added in React 18?

Of course, connecting React router to Redux store manually is not difficult at all, but I'm interested in ready solutions. Also I have been searching on the topic, but I can't find any info. Thanks in advance for answers.

Roman Karagodin
  • 740
  • 2
  • 11
  • 16

1 Answers1

5

just put that flag to ignore the old react verison npm i connected-react-router --legacy-peer-deps

Mark Wasfy
  • 167
  • 1
  • 13
  • Thanks, but just ignoring the dependency version didn't help: I have an error: "Uncaught TypeError: Cannot read properties of undefined (reading 'pathname')". – Roman Karagodin Jun 13 '22 at 15:00
  • @RomanKaragodin were you able to resolve this issue? – Daniel Aug 08 '22 at 17:15
  • @Daniel, no, I was just wondering out of curiosity. On my current work project there's React 17, so it's fine. Perhaps you can try to install an older version of `history`: I read somewhere that it is the main reason of incompatibility. – Roman Karagodin Aug 08 '22 at 17:48
  • @RomanKaragodin you got a package.json that I could use as a starter proj? – Daniel Aug 09 '22 at 06:47
  • @RomanKaragodin did you fix this issue? I am using react 18 and I can not change its version – Oussama Abouzid Sep 09 '22 at 08:49
  • No, I didn't fix that. On my current project it was decided to drop connected-react-router as outdated and implement another solution. – Roman Karagodin Sep 09 '22 at 12:38
  • 1
    What did you use instead of connected-react-router? – gyurisc Nov 10 '22 at 10:47
  • Still nothing: we're using React 17 and haven't migrated from connected-react-router yet. But it definitely would not be a problem to implement some custom solution instead - e.g. listen to location change and dispatch some action to save this data in redux store. – Roman Karagodin Jan 17 '23 at 18:05