react-router: Invariant violation after update to react-router 4.4.0
Version
4.4.0
Steps to reproduce
webpack build run with wepback-dev-server Get Invariant violation: cannot use Route or wirhRouter() outside of Router
Expected Behavior
No error, as nothing else changed but version of react-router and react-router-dom packages
Actual Behavior
index.js:19 Uncaught Invariant Violation: You should not use <Route> or withRouter() outside a <Router>
at e.exports (http://localhost:3026/bundle.js:60529:55135)
at a.computeMatch (http://localhost:3026/bundle.js:60607:26236)
at new a (http://localhost:3026/bundle.js:60607:25553)
at constructClassInstance (http://localhost:3026/bundle.js:208481:18)
at updateClassComponent (http://localhost:3026/bundle.js:211807:5)
at beginWork (http://localhost:3026/bundle.js:212764:16)
at performUnitOfWork (http://localhost:3026/bundle.js:216432:12)
at workLoop (http://localhost:3026/bundle.js:216472:24)
at HTMLUnknownElement.callCallback (http://localhost:3026/bundle.js:197315:14)
at Object.invokeGuardedCallbackDev (http://localhost:3026/bundle.js:197365:16)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 24 (3 by maintainers)
I am seeing the same thing as @mccambridge; Upgrading to
5.0.0did not fix the issue; locking to4.3.1fixes the issue. Verified that I was not mixingimportstatements, as described in the 4.4.0-beta.1 release notesSame as @mccambridge experience same kind of error, after updating both packages and main project react-router and react-router-dom version to 5.0.0. Returning back to 4.3.1 make things working.
I still had this occurring on v5, had to downgrade to 4.3.1 to get it working again as well.
Ditto here, upgrading from 4.3.1 to 5.0.0 without making any changes to the project caused:
Invariant failed: You should not use <Switch> outside a <Router>I’m using
connected-react-routerin place of my<Router/>.I’m getting this error when I import a component from one of our internal packages that contains a
RouteorLinkcomponent. Though this component is located externally, it’s always a descendant of our component tree way under theRoutercomponent. If I move the component to a local file in the project, suddenly it works without a single code change. This is causing me all kinds of problems. Not sure why the Invariant violation would fire in this case.I’m pretty sure this is a duplicate of #6630. Your
react-router-dompackage is probably pulling inreact-router4.4.0. I have already described some workarounds that you can take for now, but we are working on a more permanent fix.Let’s follow up there.
For everyone, who are trying to use the exact versions (4.3.1) as a workaround and still have their builds failing - please make sure you are NOT using
npmto install packages. Useyarn. Just to clarify, while having the exact"react-router-dom": "4.3.1"and the:in my *package.json`, I’ve tried both options:
when you use
npm iit will end up installing thereact-router4.4 version, disregarding the resolutions config. Because in the package.json of thereact-router-domit has a caret near thereact-routerdependency -"^4.3.1". Here is the resultedpackage.jsonof the resolvedreact-routerwhen you use
yarn- the proper version that is described in the resolutions sections is installed.@mccambridge @alexanderturinske @Cherviakov I’ve fixed it by deleting
node_modulesand doing ayarn(ornpm installif you will). Usingv5.0.0ofreact-router-dom.Link is a child of BrowserRouter in my app, as you can see from the second error. Using react-router and react-router-dom 4.4.0, react and react-dom 16.8.4