Comments (11)
Thanks @CharlesStover it was strange as I went into my node_modules folder and verified react-router and react-router-dom were both on 5.0. Anyways I just updated my Node/NPM versions and blew away node modules and reinstalled and got it working. Thanks for the help and nice job on this little library!
from use-react-router.
Can you share the exact version numbers that are installed?
from use-react-router.
Sure thing
"react-router": "^5.0.0",
"react-router-dom": "5.0.0",
from use-react-router.
That's ^5.0.0
, but not the exact version, e.g. you could be using 5.0.1
, but it looks like they haven't published a later version than 5.0.0, so that shouldn't be a problem.
Do you have react-router
installed in multiple places in the directory tree? For example, if you are in path/to/your-app/src/
, you may have it in path/to/your-app/node_modules/react-router
. Do you also have react-router installed in e.g. path/to/node_modules/react-router
or path/node_modules/react-router
or path/to/your-app/src/node_modules/react-router
?
Are react-router/react-router-dom installed in the same node_modules
directory and package.json file as use-react-router
?
Can you try deleting your node_modules
directory and re-installing it from scratch with npm install
or yarn
? It's possible that one package was installed with npm
while the other was installed with yarn
, which I believe could cause this error as well.
from use-react-router.
You're welcome. I'm glad it was resolved.
from use-react-router.
I'm getting the exact same, but only during tests. Using Jest and Create-React-App. react-router
and react-router-dom
are at 5.0.0
(checked node_modules). Was at Node 9, but upgraded to Node 10 without luck.
from use-react-router.
@veksen Have you tried removing your entire node modules directly and installing it again from scratch via yarn
or npm install
?
from use-react-router.
Yes, including clearing out (deleting) yarn.lock
from use-react-router.
I had the same error message and spend a lot of time to find an old react-router installation until i noticed that the issue was not the wrong react-router version but a wrong error message:
import React, {ReactElement, useContext} from 'react';
import { BrowserRouter as Router} from 'react-router-dom';
import useReactRouter from 'use-react-router';
export default function ():ReactElement {
const { history, location, match } = useReactRouter();
return <Router>...</Router>;
}
My issue was the the context is not yet created which causes the error message use-react-router may only be used with react-router@^5.
. Moving the useReactRouter a component deeper resolves my issue.
@CharlesStover maybe you can catch the error the someone wants to access the RouterContext
outside of the <Router>
and throw a better error?
from use-react-router.
@fxOne That was what I thought as I skimmed through the code and saw the error message in use when useContext
would return falsy
. In my case, I am not wrapping my tests in a <Router>
, and the old tests were testing the unconnected (non useRouter
HOC) component, so that makes sense. Perhaps let's create a new issue about the error message?
from use-react-router.
Thank you very much for that debugging information. I'm not sure I'd have found that on my own!
I'll go ahead and repurpose this issue with the newfound information.
from use-react-router.
Related Issues (19)
- Add Travis key
- [QoL] Warn on missing react-router context HOT 6
- Provide a more informative error message for [email protected] or earlier. HOT 4
- Cannot find SourceMap 'use-force-update.js.map' HOT 1
- Failed to compile HOT 2
- Any example in the docs? HOT 4
- Subscribing to location changes might be a no-op. HOT 4
- why do we need a force update? HOT 1
- Types section is missing in package.json
- Typing errors with updated @types/[email protected] HOT 2
- Pin peerDependency of react-router HOT 1
- does not read updated parameteres HOT 1
- Thank you! HOT 1
- Allow to use within MemoryRouter HOT 2
- useReactRouter may only be called within a <Router /> context HOT 5
- impossible to get params using typescript HOT 2
- Perhaps add to the docs official implementation? HOT 1
- Ask people to use 5.1 instead? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-react-router.