Connected-react-router doesn't work with React 18
Asked Answered
I

1

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: [email protected]

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 [email protected] 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.

Intranuclear answered 13/6, 2022 at 13:52 Comment(0)
G
6

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

Gobble answered 13/6, 2022 at 14:13 Comment(9)
Thanks, but just ignoring the dependency version didn't help: I have an error: "Uncaught TypeError: Cannot read properties of undefined (reading 'pathname')".Intranuclear
@RomanKaragodin were you able to resolve this issue?Enviable
@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.Intranuclear
@RomanKaragodin you got a package.json that I could use as a starter proj?Enviable
@RomanKaragodin did you fix this issue? I am using react 18 and I can not change its versionIdeogram
No, I didn't fix that. On my current project it was decided to drop connected-react-router as outdated and implement another solution.Intranuclear
What did you use instead of connected-react-router?Lakenyalaker
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.Intranuclear
Some alternatives from the internet: github.com/lagunovsky/redux-react-router (has similar API), or github.com/salvoravida/redux-first-history. Taken from Github issue in connected-react-router github.com/supasate/connected-react-router/issues/578Consecrate

© 2022 - 2024 — McMap. All rights reserved.