This will guide you through setting up Sentry with Next.js and Cloudflare Pages. An example branch with these changes is on GitHub

Run the Sentry wizard

This will run a wizard to help us set things up the way we need it to. Be sure to update the org/project to match your Sentry project.

pnpx @sentry/wizard@latest -i nextjs  --org sentry --project zonr
  1. Select sentry.io, or input your self-hosted Sentry URL (I’m using self-hosted)

    CleanShot 2025-03-01 at 06.56.30@2x.jpg

  2. Select pnpm as the package manager:

    CleanShot 2025-03-01 at 06.57.13@2x.jpg

  3. Don’t route requests through Next.js server (this doesn’t seem to work with Pages)

    CleanShot 2025-03-01 at 06.58.03@2x.jpg

  4. The next few options for things like React annotations/tracing/etc. are up to you. I’ll go ahead and enable them (the default)

    CleanShot 2025-03-01 at 06.59.53@2x.jpg

  5. Select Yes when prompted to create error page for easy testing

    CleanShot 2025-03-01 at 07.00.53@2x.jpg

  6. You may get an error that it failed to add .env.sentry-build-plugin to .gitignore - this can be safely ignored if .env* is already in .gitignore

    CleanShot 2025-03-01 at 07.01.38@2x.jpg

  7. Select Yes when prompted if we’re using CI/CD

    CleanShot 2025-03-01 at 07.02.25@2x.jpg

  8. Select “I’ll do it later” when prompted to configure CI

    CleanShot 2025-03-01 at 07.03.31@2x.jpg

  9. Go to https://dash.cloudflare.com and navigate to your Pages project → Settings → Variables and Secrets and add this token so that your builds are able to upload sourcemaps to Sentry

    CleanShot 2025-03-01 at 07.04.35@2x.jpg

Modifications to fix issues

Unfortunately, Sentry won’t work out of the box due to some issues between Next.js 15, @cloudflare/next-on-pages, and @sentry/nextjs. Follow the steps below to get a mostly working Sentry setup.

Use edge runtime in example API route (the build will fail without this)

CleanShot 2025-03-01 at 07.12.45@2x.jpg

Downgrade @sentry/nextjs to version 8.35.0

This is needed due to compatibility issues between next-on-pages and @sentry/next