question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`useRouter` returns null on the server when using "experimental-edge" runtime

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
    Binaries:
      Node: 16.16.0
      npm: 8.14.0
      Yarn: 1.22.17
      pnpm: 7.9.5
    Relevant packages:
      next: 13.0.0
      eslint-config-next: 12.3.0
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

useRouter returns null on the server

Expected Behavior

useRouter should return the router both on server and client

Link to reproduction

https://github.com/remorses/try-next-getserversideprops-edge

To Reproduce

next dev
# visit index page
# router will be null in server logs

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
remorsescommented, Dec 12, 2022

I confirm it’s fixed in canary 🥳

1reaction
huozhicommented, Dec 12, 2022

@remorses can you try the latest next? it should be already fixed by #43302 and #43192. I tested your reproduction locally it works well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useRouter is null; router.isready does not seem to work with ...
I run your code which gave an error sadly: Unhandled Runtime Error Error: Cannot read properties of undefined (reading 'isReady') Router is ......
Read more >
Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >
Next.js, useRouter hook, and testing - w11i.me
During a test the value returned by the useRouter hook appears to be either null or undefined . How to work around this?...
Read more >
next: Versions | Openbase
Convert with-cssed , with-csx , with-styled-jsx examples to TypeScript: #43018; feat(examples): use experimental edge runtime with grafbase: #42992.
Read more >
next/router | Next.js
useRouter is a React Hook, meaning it cannot be used with classes. ... It will be an empty object during prerendering if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found