PlatformsJavaScriptNext.js

Next.js

Capture exceptions from Next.js App Router, RSC, and edge with @sentry/nextjs pointed at Epure.

Use official @sentry/nextjs 7.120.0 (same JS/TS fixture line as Browser and Node). Point dsn at your Epure host. No @epure/* package.

Use this guide when one Next.js app needs client + server (+ edge) instrumentation. Do not use this for a Vite/CRA SPA (→ Browser) or a standalone Express API (→ Node). Full map: Pick your SDK.

Capture exceptions in Next.js

Install @sentry/nextjs@7.120.0, set both DSN env vars to the same Epure project, and init client, server, and edge.

Shared DSN, environment, and release options: JavaScript / TypeScript.

How do I install @sentry/nextjs?

npm install @sentry/nextjs@7.120.0

Pin 7.120.0 for the documented line. Newer majors may work; confirm with Verify.

Which env vars do I set?

Client bundles cannot read SENTRY_DSN. Set both to the same Epure project:

SENTRY_DSN=http://YOUR_PUBLIC_KEY@localhost:8080/YOUR_PROJECT_ID
NEXT_PUBLIC_SENTRY_DSN=http://YOUR_PUBLIC_KEY@localhost:8080/YOUR_PROJECT_ID

Missing NEXT_PUBLIC_SENTRY_DSN means hydration and client throws never leave the tab.

Init the Next.js SDK

Sentry JS 7.x uses three config files at the app root. Call Sentry.init in each.

// sentry.client.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  environment: "local",
  release: "my-app@1.0.0",
  tracesSampleRate: 0,
  profilesSampleRate: 0,
  replaysSessionSampleRate: 0,
  replaysOnErrorSampleRate: 0,
});

Wrap next.config with withSentryConfig so the SDK can upload source maps for the same release string.

Sentry JS v8+

v8+ moves client init to instrumentation-client.ts and adds enableTracing: false when the option exists. Keep sample rates at 0. Demangle still covers JS/TS .map files only.

What is captured?

Exceptions that reach the official Next.js handlers:

  • Client: hydration mismatches, browser-only throws
  • Server: RSC, server actions, route handlers
  • Edge: middleware and edge routes

Transactions, replay, and profiles are discarded. Leave those sample rates at 0.

How do I capture handled errors?

try {
  await charge();
} catch (error) {
  Sentry.captureException(error);
  throw error;
}

How do Next.js source maps work?

Upload JS/TS .map files for the same release as Sentry.init: Source maps.

Why does Next.js never send?

What you seeWhat to do
Client throws missingSet NEXT_PUBLIC_SENTRY_DSN (same project as SENTRY_DSN)
Failed OPTIONS from the browserAdd the app origin to EPURE_CORS_ORIGINS
401 / 403Recopy the DSN; revoked keys fail closed
202, empty IssuesEnvironment filter vs environment: "local"

Next

Can I use @sentry/browser and @sentry/node instead?

A full Next.js app should use @sentry/nextjs so client, server, and edge share one package. A separate Vite SPA plus Express API uses Browser and Node, often with one Epure project.

Will this catch App Router and Server Component errors?

Yes for exceptions that reach the official Sentry Next.js handlers (client, server, and edge init). Wire the SDK the same way Sentry’s guide shows. Only the DSN host is Epure. Confirm with Verify.

Are traces or replay stored?

No. Set traces, profiles, and replay sample rates to 0. Those item types are discarded on ingest. Exception events plus breadcrumbs stay: JavaScript overview.