Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Using useRouter with edge runtime leads to this error: Error: invariant expected app router to be mounted #56432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
joncoronel opened this issue Oct 4, 2023 · 4 comments
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@joncoronel
Copy link

joncoronel commented Oct 4, 2023

Link to the code that reproduces this issue

https://github.com/joncoronel/testing-next

To Reproduce

  1. Start the application in a local dev server
  2. Load the root page: i.e. http://localhost:3000/
  3. Check server logs for error.
  4. Open browser dev tools, disable caching, and then reload the page while inspecting the <html> element.

Current vs. Expected behavior

Using edge runtime on a route/page and then using useRouter in a client component within that page should not lead to any error. Currently it causes both an error in the dev server logs and also causes an error in the page html element on initial load or reload: <html id="__next_error__">. It disrupts the loading of fonts since they are passed as variable in the html element.

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
Binaries:
  Node: 20.7.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 13.5.5-canary.1
  eslint-config-next: 13.4.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.0.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Additional context

This error has been occurring since next 13.4.8. I tested 13.4.7 and it does not have this error. I also updated to 13.5.4 and the issue is still present as well as the latest canary build.
This error specifically occurs when using edge runtime and useRouter. Removing either of them removes this error.

@joncoronel joncoronel added the bug Issue was opened via the bug report template. label Oct 4, 2023
@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. labels Oct 4, 2023
@jinowac
Copy link

jinowac commented Oct 26, 2023

I am getting same issue

@joncoronel
Copy link
Author

I am getting same issue

This was fixed with a recent release a couple weeks ago. I would try updating.

@alvis
Copy link

alvis commented May 2, 2024

@joncoronel has it been fixed on your side?

@farhansadikgalib

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

4 participants