Skip to content
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

Annoying Error: "invariant expected app router to be mounted" #951

Open
gandli opened this issue Sep 12, 2024 · 0 comments
Open

Annoying Error: "invariant expected app router to be mounted" #951

gandli opened this issue Sep 12, 2024 · 0 comments

Comments

@gandli
Copy link

gandli commented Sep 12, 2024

I am using the Simple Next.js template which uses Vercel Postgres as the database and Kysely as the query builder.

After completing all the setup steps, I encountered the following error when running pnpm dev:

 pnpm dev

> [email protected] dev C:\Users\sec\Desktop\postgres-drizzle
> next dev

  ▲ Next.js 13.5.4
  - Local:        http://localhost:3000
  - Environments: .env.development.local

 ✓ Ready in 2.5s
Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
 ✓ Compiled /page in 2.1s (780 modules)
 ⨯ Error: invariant expected app router to be mounted
    at RefreshButton (./components/refresh-button.tsx:14:78)
 ✓ Compiled in 260ms (258 modules)
 ⨯ Error: invariant expected app router to be mounted
    at RefreshButton (./components/refresh-button.tsx:14:78)
 ✓ Compiled /favicon.ico/route in 801ms (39 modules)

components\refresh-button.tsx

'use client'

import { useRouter } from 'next/navigation'
import { useTransition } from 'react'

export default function RefreshButton() {
 const router = useRouter()
 const [isPending, startTransition] = useTransition()

 return (
   <button
     className={`${
       isPending ? 'cursor-not-allowed text-gray-400' : ''
     } text-sm text-gray-500 hover:text-gray-900`}
     disabled={isPending}
     onClick={() => {
       startTransition(() => {
         router.refresh()
       })
     }}
   >
     {isPending ? 'Refreshing...' : 'Refresh'}
   </button>
 )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant