Next.js error tracking your coding agent can read
Updated 2026-11-22
In production, Next.js hides server component errors behind a digest ("The specific message is omitted in production builds"). Runheed records the real error on the server through the onRequestError hook in instrumentation.ts, with the route and request, and your coding agent reads it over MCP.
Set it up
1.Install the SDK.
terminalbashnpm install https://runheed.com/dl/runheed-0.1.7.tgz2.Create instrumentation.ts in the project root (or src/). register() runs once per server start; onRequestError runs for every uncaught server error in the Node.js runtime. The SDK batches events for up to 5 seconds, so the hook awaits flush() to send right away: on Vercel the function can be frozen as soon as the response goes out.
instrumentation.tstypescriptexport async function register() { if (process.env.NEXT_RUNTIME === 'nodejs') { const runheed = (await import('runheed')).default; runheed.init({ dsn: process.env.RUNHEED_DSN!, environment: process.env.NODE_ENV }); } } export async function onRequestError( err: unknown, request: { path: string; method: string }, context: { routePath: string; routeType: string }, ) { // Keep this as a wrapping if: Next also compiles this file for the Edge runtime, and only this form lets the // bundler drop the import there. An early return fails with "Can't resolve 'os'". if (process.env.NEXT_RUNTIME === 'nodejs') { const runheed = (await import('runheed')).default; runheed.captureException(err as Error, { path: request.path, method: request.method, routePath: context.routePath, routeType: context.routeType, }); // Send now: on Vercel and other serverless hosts the function can freeze right after the response. await runheed.flush(); } }3.Set RUNHEED_DSN in your deploy platform's environment, then connect your agent (one command for Claude Code).
terminalbashclaude mcp add --transport http runheed https://runheed.com/api/mcp
The npm and PyPI releases are not out yet, so these commands install the same package files straight from runheed.com. Nothing else changes when the registry versions ship.
What it catches
- Server component and route handler errors, including the real message behind the production digest
- Server action failures
- Errors in API routes and proxy code running on the Node.js runtime
What it does not do
- Edge runtime routes are skipped in this setup (the SDK uses Node.js APIs)
- Browser errors are captured when the frontend reports through @sentry/react or @sentry/browser with the project's Sentry SDK DSN (see /for/react)
Then ask your agent
> which server errors came in since the last deploy? read the real message behind the digest, fix the top one and resolve it with the commit hash
Connect Runheed first: Claude Code, Cursor or another client. Then see how the agent fixes and resolves an error.
Common Next.js errors
- Error: An error occurred in the Server Components render. The specific message is omitt...
- Hydration failed because the server rendered HTML didn't match the client. As a result ...
- Error: Event handlers cannot be passed to Client Component props.
- Error: Only plain objects, and a few built-ins, can be passed to Client Components from...
- ReferenceError: window is not defined
- Error: Route "/orders/[id]" used `params.id`. `params` should be awaited before using i...
- Error: NEXT_REDIRECT
- useSearchParams() should be wrapped in a suspense boundary at page "/search".
- You're importing a module that depends on `useState` into a React Server Component modu...
- Error: Objects are not valid as a React child (found: object with keys {id, name, total...
- Error: Element type is invalid: expected a string (for built-in components) or a class/...
- Error: Too many re-renders. React limits the number of renders to prevent an infinite l...
- PrismaClientInitializationError: Can't reach database server at `db.example.com:5432`