Skip to main content
⚡ OpenDevDocs
Next.js
frontendnextjsTroubleshootingIntermediate

Common Next.js Errors & Fixes

Troubleshoot and resolve frequent Next.js App Router errors, hydration mismatches, and component boundary issues.

Verified: 2026-09-30
Tested on:nextjs 16.x, react 19.x
Platforms:
webnode
#nextjs#debugging#hydration#errors#troubleshooting

Overview

This guide explains the most common errors encountered when developing with the Next.js App Router and provides clear solutions to fix them.


1. Hydration Failed / Mismatch

Error Message

Error: Hydration failed because the initial UI does not match what was rendered on the server.

Why It Happens

The HTML rendered on the server differs from the initial DOM tree generated by React in the browser. Common triggers include using Date.now(), Math.random(), window.innerWidth, or localStorage during initial server render.

Quick Fix

Defer browser-only attributes until after mounting using useEffect:

'use client';

import { useState, useEffect } from 'react';

export function FormattedTime() {
  const [time, setTime] = useState<string | null>(null);

  useEffect(() => {
    setTime(new Date().toLocaleTimeString());
  }, []);

  if (!time) return <span>Loading time...</span>;
  return <span>{time}</span>;
}

2. useState / useEffect in Server Component

Error Message

Error: You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with "use client".

Quick Fix

Add 'use client'; as the very first line of your component file:

'use client';

import { useState } from 'react';

export function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}

3. Dynamic Server Usage / Uncached Headers

Error Message

Error: Dynamic server usage: Route /dashboard couldn't be rendered statically because it used `cookies` or `headers`.

Why It Happens

A route configured for static generation accessed dynamic request properties (cookies(), headers(), or searchParams).

Quick Fix

If the page is meant to be dynamic, declare dynamic = 'force-dynamic' or embrace dynamic server rendering:

export const dynamic = 'force-dynamic';

4. params / searchParams Await Error

Error Message

Error: Route "/posts/[id]" used `params.id`. `params` should be awaited before using its properties.

Why It Happens

In Next.js versions 15 and 16, params and searchParams in Page components and Route Handlers are asynchronous Promises.

Quick Fix

Always await params:

// ✅ Correct
interface PageProps {
  params: Promise<{ id: string }>;
}

export default async function Page({ params }: PageProps) {
  const { id } = await params;
  return <h1>Post: {id}</h1>;
}

5. Passing Non-Serializable Props across RSC Boundaries

Error Message

Error: Event handlers cannot be passed to Client Component props from a Server Component.

Why It Happens

Server Components serialize their props over the network as JSON. Functions, class instances, and event handlers (onClick, onFocus) cannot be serialized.

Quick Fix

Move the event handler inside the Client Component itself, or pass a Server Action ('use server') function instead.

On this page