Next.js Discord

Discord Forum

error Error: invariant expected app router to be mounted at

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
I'm getting this error:
error Error: invariant expected app router to be mounted
    at HomePage

whenever I use both the useRouter hook and then export const runtime = "edge"; in the route.

This error was introduced at some point after next 13.4.4.

Minimal reproduction: https://github.com/joncoronel/testing-mantine-7

22 Replies

I'm sorry, I saw the above snippet and got confused.
if you disable swcMinify, does it work? (i kinda doubt it tho)
@riský if you disable `swcMinify`, does it work? (i kinda doubt it tho)
Giant pandaOP
Nope, just tried it.
To clarify(just edited the post to include it), this error occurs directly as a result of using export const runtime = "edge"; on the route and then using useRouter within a client component in that route.
yeah i gathered that
imo as it seems like a bug, you should use this repo and submit issue
as everything looks normal (and you say it works without edge)
Oh, you already at 13.5
@dumbboy Does this release fix this for you: https://github.com/vercel/next.js/releases/tag/v13.4.8-canary.1
Giant pandaOP
Yeah I can confirm this error does not occur on 13.4.4 but starting happening in some version afterwards.
Seems like this is the exact issue you are facing? https://github.com/vercel/next.js/issues/55013
@riský as everything looks normal (and you say it works without edge)
Giant pandaOP
Yep error is gone once I remove the edge runtime. This wasn't really an issue before but it messes with UI component libraries like Mantine and NextUI since the error prevents color scheme styling from applying on initial load.
@dumbboy Seems like this is the exact issue you are facing? https://github.com/vercel/next.js/issues/55013
Giant pandaOP
Yep exact same issue. So based on that post, this bug was introduced with 13.4.8
@riský lol i should have actualy looked at issues...
I don't google for these latest version issues, I just search keywords in Github Issues
So, according to this comment: https://github.com/vercel/next.js/issues/55013#issuecomment-1712330213.

It should be fixed in next@13.4.8-canary.1 version right?
@dumbboy So, according to this comment: https://github.com/vercel/next.js/issues/55013#issuecomment-1712330213. It should be fixed in `next@13.4.8-canary.1` version right?
Giant pandaOP
I think they're trying to say the issue was introduced with that update spceifically
SO, the issue is still open IG