Next.js Discord

Discord Forum

Next.js Deploy issue

Unanswered
American black bear posted this in #help-forum
Open in Discord
Avatar
American black bearOP
Error: NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted
12:59:39 PM: at h (/opt/build/repo/.next/server/chunks/664.js:1:29556)
12:59:39 PM: at _ (/opt/build/repo/.next/server/pages/_app.js:1:1289)


Hello everyone.
There are some issues happened when I deploy the Next.js app to Netlify.
How can I fix this?

12 Replies

Avatar
Import useRouter from next/navigation not next/router
Avatar
American black bearOP
I use this but there is another issue happened. TypeError: Cannot read properties of null (reading 'pathname')
Avatar
Use usePathname instead of useRouter to get the pathname
Avatar
American black bearOP
thanks
I will try
Oh no. Aonther issue.
TypeError: Cannot read properties of null (reading 'startsWith')
2:51:08 PM: at u (/opt/build/repo/.next/server/pages/_app.js:1:1492)


import { usePathname } from "next/navigation";
import { SessionProvider } from "next-auth/react";
import { ThirdwebProvider } from "thirdweb/react";

import { kgRedHands } from "../lib/fonts";
import Layout from "./dashboard/layout";
import "../styles/globals.css";

function MyApp({ Component, pageProps }) {
const pathname = usePathname();

return (
<ThirdwebProvider
activeChain="ethereum"
clientId={process.env.NEXT_PUBLIC_THIRDWEB_CLIENT_ID}
>
<SessionProvider session={pageProps.session}>
<main className={kgRedHands.className}>
{pathname.startsWith("/dashboard") ? (
<Layout>
<Component {...pageProps} />
</Layout>
) : (
<Component {...pageProps} />
)}
</main>
</SessionProvider>
</ThirdwebProvider>
);
}

export default MyApp;
cna you help me?
Avatar
This code is for the pages router, why are you using the app router?
Avatar
American black bearOP
how should I do?
Avatar
Well…
I suggest you take the learn course at nextjs.org/learn and learn Nextjs because from what you’ve done so far, I know no matter what I try I won’t be able to help you
Also, read the documentation at nextjs.org/docs
Avatar
American black bearOP
okay