nextjs type_error ai_generated true

TypeError: Cannot read properties of undefined (reading 'searchParams')

ID: nextjs/cannot-read-properties-searchparams

Also available as: JSON · Markdown
88%Fix Rate
88%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
14 active

Root Cause

searchParams is now a Promise in Next.js 15+, or page component not receiving props correctly.

generic

Workarounds

  1. 92% success Ensure page component accepts { searchParams } prop correctly
    export default function Page({ searchParams }: { searchParams: { q?: string } })

    Sources: https://nextjs.org/docs/app/api-reference/file-conventions/page

  2. 88% success Use useSearchParams() hook in client components
    const searchParams = useSearchParams()

    Sources: https://nextjs.org/docs/app/api-reference/functions/use-search-params

Dead Ends

Common approaches that don't work:

  1. Use window.location.search instead 75% fail

    Doesn't work in server components

  2. Default to empty object 60% fail

    Silently ignores URL parameters

Error Chain

Frequently confused with: