react-admin: ViteJS - Uncaught Error: useRoutes() may be used only in the context of a component

What you were expecting: react-admin should render as expected

What happened instead: react-router does not render any routes, and instead throws an exception:

Uncaught Error: useRoutes() may be used only in the context of a <Router> component

Steps to reproduce:

  1. Set up a new Vite project using react-ts template
  2. Follow tutorial to set up a react-admin component
  3. Launch app

Related code:

insert short code snippets here

Other information:

Environment

  • React-admin version:
  • Last version that did not exhibit the issue (if applicable):
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):
Uncaught Error: useRoutes() may be used only in the context of a <Router> component.
    invariant index.tsx:24
    useRoutes index.tsx:642
    Routes index.tsx:344
    React 12
    unstable_runWithPriority scheduler.development.js:468
    React 4
    unstable_runWithPriority scheduler.development.js:468
    React 3
    workLoop scheduler.development.js:417
    flushWork scheduler.development.js:390
    performWorkUntilDeadline scheduler.development.js:157
    js scheduler.development.js:180
    js scheduler.development.js:645
    __require chunk-CEDYW5NB.js:11
    js index.js:6
    __require chunk-CEDYW5NB.js:11
    React 2
    __require chunk-CEDYW5NB.js:11
    js React
    __require chunk-CEDYW5NB.js:11
    <anonymous> react-dom:1
index.tsx:24:19

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 23 (6 by maintainers)

Most upvoted comments

Not yet. For now I’m staying with fixed react-router-dom: 6.3.0

I had the same issue using react-router@6.4.4. After that, changing to 6.3.0 didn’t solve the problem. I’m using pnpm and had two versions of react-router in /node_modules/.pnpm/.

Deleted the node_modules directory and deleted pnpm-lock.yaml. I solved it by running pnpm install afterwards.

Thanks @septentrion-730n . Will investigate a bit more on my end. Appreciate the quick turnaround!