error.js file defines a fallback UI for unexpected runtime errors within a route segment. It wraps the segment and its nested children in a React Error Boundary.
app/dashboard/error.js
Props
An
Error object forwarded to the Client Component.- In development — includes the original error
messagefor easier debugging - In production — shows a generic message to avoid leaking sensitive information. Use
error.digestto correlate with server-side logs.
The human-readable error message. For errors from Client Components, this is the original message. For Server Component errors, this is a generic message with an identifier to match server-side logs.
An automatically generated hash of the thrown error. Use it to match the error in your server-side logs.
Re-fetches and re-renders the error boundary’s children. If successful, the error fallback is replaced with the re-rendered content.Use this for transient errors where retrying is likely to succeed.
Clears the error state and re-renders the error boundary’s children without re-fetching. Use this when you want to clear the error state without a network request.In most cases, prefer
unstable_retry() over reset().Behavior
error.jswrapsloading.js,not-found.js,page.js, and nestedlayout.jsfiles in an error boundary- It does not wrap the
layout.jsortemplate.jsin the same segment - To handle errors in the root layout, use
global-error.js - Throwing inside an error component bubbles the error up to the parent error boundary
Examples
Basic error boundary
app/dashboard/error.js
Logging errors to a reporting service
app/dashboard/error.js
Global error
To handle errors in the root layout or template, useapp/global-error.js. This file replaces the entire root layout when active, so it must include its own <html> and <body> tags.
app/global-error.js
global-error.js must be a Client Component. The metadata export and generateMetadata are not supported. Use React’s <title> component as an alternative.Version history
| Version | Changes |
|---|---|
v16.2.0 | unstable_retry prop added |
v15.2.0 | global-error also displayed in development |
v13.1.0 | global-error introduced |
v13.0.0 | error introduced |
