Next.js: You have a Server Component that imports next/router. Use next/navigation instead
next/router (Pages Router) was imported in an App Router component.
You have a Server Component that imports next/router. Use next/navigation insteadError: NextRouter was not mounted. next/router App RouterYou are importing next/router in the app directorynext/router in the app dir use next/navigation instead Meaning
In the App Router use useRouter, usePathname, useSearchParams from next/navigation inside Client Components ("use client"). router.query and events don't exist; read useParams()/useSearchParams(). In Server Components use redirect()/params.
Common causes
import { useRouter } from "next/router"inapp/- Copied Pages Router code
- Third-party component using next/router in App Router
- Using
router.query - Router events like
routeChangeStart
⚡ Quick fix
import { useRouter } from "next/navigation"- Add
"use client"for hooks - Replace
router.querywithuseParams()/useSearchParams()
Detailed fix by platform
Next.js
"use client"; import { useRouter, usePathname } from "next/navigation";
How to diagnose
- Import — next/router in app/?
- Directive — use client?
- API — query replaced?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- createContext only works in Client Components Next.js: You're importing a component that needs createContext. It only works in a Client Component but none of its parents are marked with "use client"
- Failed prop type: The prop href expects a string or object in <Link> Next.js: Error: Failed prop type: The prop `href` expects a `string` or `object` in `<Link>`, but got `undefined` instead
- Invalid <Link> with <a> child. Please remove <a> Next.js 13+: Error: Invalid <Link> with <a> child. Please remove <a> or use <Link legacyBehavior>
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026