Code Monkey home page Code Monkey logo

Comments (11)

mikecfisher avatar mikecfisher commented on July 19, 2024 2

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.

quisido avatar quisido commented on July 19, 2024

Can you share the exact version numbers that are installed?

from use-react-router.

mikecfisher avatar mikecfisher commented on July 19, 2024

Sure thing

    "react-router": "^5.0.0",
    "react-router-dom": "5.0.0",

from use-react-router.

quisido avatar quisido commented on July 19, 2024

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.

quisido avatar quisido commented on July 19, 2024

You're welcome. I'm glad it was resolved.

from use-react-router.

veksen avatar veksen commented on July 19, 2024

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.

image

from use-react-router.

quisido avatar quisido commented on July 19, 2024

@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.

veksen avatar veksen commented on July 19, 2024

Yes, including clearing out (deleting) yarn.lock

from use-react-router.

fxOne avatar fxOne commented on July 19, 2024

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.

veksen avatar veksen commented on July 19, 2024

@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.

quisido avatar quisido commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.