Next.js errors and fixes
Errors from the Next.js React framework: hydration mismatches, App Router client/server boundaries, build-only failures and environment variables.
11 Next.js errors below. Each page shows the exact error text, what it means, likely causes and a step-by-step fix.
Updated .
Next.js errors at a glance
| Error | Most common cause | First thing to try |
|---|---|---|
| Hydration failed because the initial UI does not match what was rendered on the server | Using browser-only values during render (window, localStorage, Date.now(), Math.random()). | Check the console for the specific element React complains about and fix invalid nesting first. |
| Text content does not match server-rendered HTML | Dates/times formatted with the user's locale or time zone. | Format dates with an explicit time zone and locale so server and client agree. |
| ReferenceError: window is not defined | Accessing window/document at the top level of a module or during render. | Access browser globals inside useEffect, which only runs in the browser. |
| You're importing a component that needs useState. It only works in a Client Component | Using React hooks in a file under app/ without the "use client" directive. | Add the directive as the very first line of the file that uses hooks. |
| async/await is not yet supported in Client Components | Adding "use client" to a page that does `export default async function`. | Option A. |
| Module not found: Can't resolve '...' | The package isn't installed (or is only installed locally, not in package.json). | Install the package and make sure it is saved to package.json. |
| Invalid src prop on next/image, hostname is not configured | Loading an image from a new domain (e.g. | Add the host to remotePatterns in next.config. |
| Dynamic server usage: Route couldn't be rendered statically | Calling cookies() or headers() in a page or layout that Next.js assumes is static. | Mark the route as dynamic. |
| Environment variable is undefined in the browser | Variable not prefixed with NEXT_PUBLIC_. | Rename the variable for client use (never do this for secrets). |
| Objects are not valid as a React child | Rendering {user} instead of {user.name}. | Render a specific field or convert to a string. |
| useSearchParams() should be wrapped in a suspense boundary | Calling useSearchParams() in a component rendered by a static page without Suspense. | Wrap the component that uses search params in Suspense. |
All Next.js fixes
- Hydration failed because the initial UI does not match what was rendered on the server
React rendered HTML on the server, then rendered again in the browser and got a different result. - Text content does not match server-rendered HTML
A text node rendered differently on the server and in the browser. - ReferenceError: window is not defined
Code that touches a browser global (window, document, localStorage) ran on the server during server rendering or build, where those globals don't exist.. - You're importing a component that needs useState. It only works in a Client Component
In the App Router every component is a Server Component unless marked otherwise. - async/await is not yet supported in Client Components
A component marked "use client" was declared as an async function. - Module not found: Can't resolve '...'
The bundler could not locate an imported file or package.. - Invalid src prop on next/image, hostname is not configured
next/image only optimizes remote images whose URL matches an entry in images.remotePatterns. - Dynamic server usage: Route couldn't be rendered statically
During build Next.js tried to prerender a route statically, but the route reads request-time data (cookies(), headers(), searchParams), which is only available per request.. - Environment variable is undefined in the browser
Next.js only exposes environment variables to browser code if their name starts with NEXT_PUBLIC_. - Objects are not valid as a React child
JSX tried to render a plain object. - useSearchParams() should be wrapped in a suspense boundary
During a production build of a statically rendered page, a client component calls useSearchParams() without a <Suspense> boundary, so Next.js would have to client-render the whole page..
Related error categories
- React & Next.js rendering errors: 5 pages
- Next.js App Router & config errors: 6 pages
- Vercel build & deploy errors: 8 pages
Not sure which one you have? Take the quiz →
Other platforms
Vercel · Supabase · Stripe · Cursor · Lovable · Bolt · Rocket.new · Replit
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy