-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: invariant expected app router to be mounted #24722
Comments
We're also facing this issue using storybook We notice this behavior since the peer dependency Edit: after investigating further, the issue does not seem to be the upgrade of the babel-core version itself, but rather a mismatch between babel-core-versions between different packages, i.e. having one use After installing |
having this issue with next |
Can someone provide a reproduction? |
Found the issue, it was on my side, so in my case, while on const meta = {
title: 'Auth/Register',
component: Register,
decorators: [
(Story) => (
<StorybookLayout>
<Story />
</StorybookLayout>
),
],
parameters: {
layout: 'centered',
+ nextjs: {
+ appDirectory: true,
+ },
},
tags: ['autodocs'],
} satisfies Meta<typeof Register>;` |
@dfd1123 Can you remove the render functions and the template? For these simple argument mapping it is not necessary. Storybook does this under the hood. Second, do you have some custom add-ons or decorators in place? |
I'll put a reproduction below.I'm also running into the same issue and it's really bothering me. https://github.com/mecaota/bugged-nextjs/tree/7122c366fa9bfb465a6b8114875d258b48cb66a0 |
Is there any workarounds for this issue? EDIT: |
I approve this message. |
Any updates on that? I've also tried using the |
For everyone having this issue, I've found a workaround using the import { AppRouterContext } from "next/dist/shared/lib/app-router-context.shared-runtime";
import mockRouter from "next-router-mock";
const withRouter: Decorator = (Story, context) => (
<AppRouterContext.Provider value={mockRouter as any}>
<Story />
</AppRouterContext.Provider>
); |
@MichaelCasaDev thx for the workaround. Great idea! import {
AppRouterContext,
type AppRouterInstance,
} from 'next/dist/shared/lib/app-router-context.shared-runtime';
const meta = {
decorators: [
(Story) => (
<AppRouterContext.Provider value={{} as AppRouterInstance}>
<Story />
</AppRouterContext.Provider>
),
],
}; |
@mecaota Your reproduction does not set up the This documentation will also be available soon on the official Storybook docs. |
@isBatak Your reproduction doesn't bootstrap. But I can see that you are not setting @isBatak, @MichaelCasaDev @MichaelCasaDev You are mentioning that I am closing this issue for now because it seems that the required parameter is not set accordingly. If |
@valentinpalkovic please reopen this issue because your suggested solution does not work. Please read my original issue #25612. |
Can you point me to the Next.js documentation where it explicitly says that |
@valentinpalkovic I can't find any documentation but I can prove that I would say it's there for easier migration form To clarify:
I don't see why would this be a problem. |
@isBatak |
The code of @MichaelCasaDev and @isBatak did:
|
same here, but it worked before. Seems like some version change break the thing under some circumstances |
thnks, that works for me. |
Describe the bug
The component that imports next/navigation and uses useRouter generates an error saying 'Error: invariant expected app router to be mounted'. I am using storybook version 7.5.2 and next14 version. And I also set nextjs: { appDirectory: true } in the parameters.
However, the error does not go away and continues to occur. Did I possibly do something wrong??
To Reproduce
No response
System
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: