Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Next.js Server Components render error in production

The generic Server Component error hides the real message. Recover the digest, read the server logs, and report the cause without leaking internals.

~5 min readNext.js
#nextjs#server-components#error-handling#production
Bold white headline reading RENDER HIDDEN with a Next.js server crate masking an amber error card on the right.

Introduction & Quick Summary

A production Next.js deployment shows users a generic crash page and the log says only this:

code
Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details.
digest: "3563520567"

Nothing in that text identifies the component, the thrown value, or the request. Next.js deliberately replaces the real message with a digest in production builds, because server error text can carry environment values, database errors, or internal paths. The error is real and it happened during server rendering of a React Server Component; only the text is hidden.

Where it appears:

  • A server component throws during render, in a page, layout, or route segment.
  • Data fetching inside a server component rejects and the rejection is not caught.
  • A prop passed from a server component to a client component is not serializable.
  • The error only reproduces on the deployment, never in next dev.

Quick answer: take the digest from the response or the client error, find the matching line in the server logs, and fix the throw. Then add an error.tsx boundary that logs the digest with your own context so the next occurrence is one query away.

Core Mechanics, Signatures & Reproducible Setup

During a production render, Next.js catches the thrown value on the server, hashes it into a digest, and sends only the digest plus a generic message to the browser. The full error goes to the server console, which in Vercel is the function log for that invocation.

tsx
// app/dashboard/page.tsx export default async function Page() { const res = await fetch(process.env.API_URL!, { cache: "no-store" }); const data = await res.json(); // if API_URL is undefined, this throws return <h1>{data.title}</h1>; }
bash
# what the browser receives in production {"digest":"3563520567"} # what the function log holds TypeError: Failed to parse URL from /api/title at new Request (node:internal/deps/undici/undici:12756:25) at async Page (app/dashboard/page.tsx:4:15) digest: 3563520567

The digest is the join key: it is stable for one error signature within a build, so searching the deployment logs for it returns the throwing stack.

Related messages that look similar but mean different things:

MessageWhere it comes fromWhat it means
An error occurred in the Server Components renderserver render, productionthrow during RSC render, message redacted
Hydration failed because the server rendered HTML didn't matchclient, hydrationmarkup mismatch, not a server throw
Functions cannot be passed directly to Client Componentsbuild or rendernon-serializable prop across the boundary
Application error: a server-side exception has occurredapp router shellthe same throw, before any boundary handled it
Error: connect ECONNREFUSED in the log onlyserverreal message is in logs, digest in response
tsx
// app/broken/page.tsx export default async function Broken() { const value = process.env.MISSING_VALUE; if (!value) throw new Error("MISSING_VALUE is not set"); return <p>{value}</p>; }

Run next build && next start and visit /broken: the browser shows the generic message while the terminal prints the real error with a digest.

Key Comparison Table

Diagnosis routeWhat you getCost
Digest plus deployment logsexact stack with file and lineneeds log access for that deployment
next dev reproductionreal message immediatelymay not reproduce environment-specific throws
Structured logging in the componentyour own fields next to the digestextra code, one line per throw site
error.tsx client boundarydigest and request path in the browsercatches segment errors, not layout errors
global-error.tsxcatch-all for root layout throwsreplaces the whole document
Sentry or OpenTelemetry instrumentationstack, release, request contextsetup and a third-party dependency

Choosing where to catch:

BoundaryCatchesDoes not catch
error.tsx in a segmenterrors below that segment, client and servererrors in its own layout
global-error.tsxroot layout and root page throwsnothing above it, it is the top
route handler try/catchAPI route throwspage render throws
instrumentation.ts onRequestErrorevery server error, with digestbrowser-only errors

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Find the digest and match it in the deployment log

The digest reaches the client in the error object passed to a boundary, in the JSON response of the RSC request, and in the Vercel log line. Start from the boundary, because the browser holds nothing else.

tsx
// app/error.tsx "use client"; export default function Error({ error, reset, }: { error: Error & { digest?: string }; reset: () => void; }) { console.error("render-failed", { digest: error.digest, path: window.location.pathname, at: new Date().toISOString(), }); return ( <div> <h2>Something failed while rendering this page.</h2> <p>Reference: {error.digest ?? "unknown"}</p> <button onClick={() => reset()}>Try again</button> </div> ); }

With the digest and path in one log line, the search is one query.

2. Log the real error on the server before it is redacted

Next.js logs the full error itself, but your own logging can add the tenant, route, and input the framework does not know.

ts
// lib/log.ts export function logServerError(scope: string, err: unknown, extra: Record<string, unknown> = {}) { const e = err instanceof Error ? err : new Error(String(err)); console.error("[server-error]", { scope, message: e.message, stack: e.stack, ...extra }); throw e; // let Next.js hash and redact as usual }

Call it in the catch of the page that renders the data: the log line and the framework digest land in the same invocation, so a timestamp also correlates them.

3. Distinguish a serialization failure from a render throw

Passing a function, a class instance, or a Date method across the server to client boundary fails with its own message in development, and shows up as the generic render error in production.

tsx
// fails: handler is not serializable export default function Page() { return <ClientCard onClick={() => console.log("x")} when={new Date()} />; }
tsx
// fix: pass data, define the handler inside the client component export default function Page() { return <ClientCard whenIso={new Date().toISOString()} />; }
tsx
"use client"; export function ClientCard({ whenIso }: { whenIso: string }) { return <button onClick={() => console.log(whenIso)}>{whenIso}</button>; }

Dates, Maps, Sets, and class instances survive only as plain values. Convert at the boundary so the boundary never has to throw.

4. Catch the throw where the data enters

The most common production throw is an unvalidated response. Parse and validate at the fetch, so the failure names the endpoint instead of surfacing as a render crash.

ts
type Report = { id: string; title: string }; async function loadReports(): Promise<Report[]> { const res = await fetch(`${process.env.API_URL}/reports`, { cache: "no-store" }); if (!res.ok) throw new Error(`reports ${res.status}`); const body: unknown = await res.json(); if (!Array.isArray(body)) throw new Error("reports: expected an array"); return body as Report[]; }

Check the payload shape with the JSON tool before writing the guard.

5. Handle the error without hiding it

An error.tsx that returns null passes the audit and hides the incident. Return a stable message, keep the digest, and log once. Never render error.message in production: for a server throw it is the generic string, and for a client throw it can contain user input.

tsx
"use client"; export default function SegmentError({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { return ( <section role="alert"> <h2>This section could not be loaded.</h2> {error.digest ? <code>{error.digest}</code> : null} <button onClick={reset}>Reload section</button> </section> ); }

Common Compilation/Runtime Mistakes & Version Gotchas

Assuming next dev shows the same error. Development renders the real message and a stack overlay, so a bug that needs a production build or a real environment looks fine locally. Reproduce with next build && next start and the same environment before you debug.

Catching nothing because the boundary is misplaced. A segment's error.tsx does not catch a throw in its own layout.tsx. Put the boundary in the parent segment, or add global-error.tsx for the root.

Reading environment variables in a client component. process.env.X in a "use client" file is inlined at build time and is undefined at runtime for non-public names. The throw then happens during render, on the server, from a client file, and reads like a server error. Use NEXT_PUBLIC_ names deliberately, or read the value on the server and pass it down.

Swallowing the throw and returning undefined. Returning nothing from a server component produces a different error (Element type is invalid), and the original cause is now two errors away from the log.

Version differences worth knowing. Next.js 15 and 16 require await on params and searchParams in pages, layouts, and route handlers; a missing await throws at render time and arrives as a digest in production. Next.js 16 also moves request interception from middleware to the proxy file, so an auth throw may now surface as a render error. Check package.json before debugging.

Correlating with the outside world. When the crash starts at a specific minute, check the response codes with the status codes reference and diff the changed files with Diff first. Most production-only render errors follow a config or environment change, not a logic change.

Reference material: Server and Client Components and the error file convention.

Official references

primary documentation

The Next.js documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Next.js work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Next.js guides

More in Next.js

All Next.js guides

The guides filed next to this one in Next.js, in library order.