Title: `Sentry.captureException`/`captureMessage` break Next.js prerendering with Cache Components enabled · Issue #21333 · getsentry/sentry-javascript · GitHub
Open Graph Title: `Sentry.captureException`/`captureMessage` break Next.js prerendering with Cache Components enabled · Issue #21333 · getsentry/sentry-javascript
X Title: `Sentry.captureException`/`captureMessage` break Next.js prerendering with Cache Components enabled · Issue #21333 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/21333
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Sentry.captureException`/`captureMessage` break Next.js prerendering with Cache Components enabled","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nextjs\n\n### SDK Version\n\n10.56.0\n\n### Framework Version\n\nNext.js 16.2.7\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\nhttps://github.com/qnten/sentry-cache-components-repro\n\n```tsx\nexport default async function Home({ params }: { params: Promise\u003c{ id: string }> }) {\n\tconst { id } = await params;\n\tif (id === \"exception\") {\n\t\tSentry.captureException(new Error(\"Test error\"));\n\t\treturn `Error captured for id exception`;\n\t}\n\tif (id === \"message\") {\n\t\tSentry.captureMessage(\"Test message\");\n\t\treturn `Message captured for id message`;\n\t}\n\treturn `Hello, ${id}!`;\n}\n```\n\n### Steps to Reproduce\n\n1. Set up `@sentry/nextjs` in a Next.js 16.2.7 app with `cacheComponents: true` in `next.config.ts`.\n2. Create a dynamic route `app/[id]/page.tsx` with `generateStaticParams` returning `[{ id: \"test\" }]` and conditional Sentry calls for `/exception` (using `captureException`) and `/message` (using `captureMessage`) as shown above.\n3. Run `next dev` and visit `/exception` and `/message`.\n4. Run `next build`.\n\n### Expected Result\n\nCalling `Sentry.captureException` or `Sentry.captureMessage` inside a Server Component should work correctly when the page is (re)generated, for example during build, ISR or on-demand revalidation on Vercel.\n\n### Actual Result\n\n#### `next dev`\n\nVisiting `/exception` works fine in the dev server.\n\nVisiting `/message` breaks with:\n\n```\n[browser] Error: Route \"/[id]\" used `new Date()` before accessing either uncached data\n(e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and\n`searchParams`). Accessing the current time in a Server Component requires reading one of\nthese data sources first. Alternatively, consider moving this expression into a Client\nComponent or Cache Component.\nSee more info here: https://nextjs.org/docs/messages/next-prerender-current-time\n\n at Module.createEventEnvelopeHeaders\n (node_modules/.pnpm/@sentry+core@10.56.0/node_modules/@sentry/core/src/utils/envelope.ts:258:14)\n at Module.createEventEnvelope\n (node_modules/.pnpm/@sentry+core@10.56.0/node_modules/@sentry/core/src/envelope.ts:106:27)\n at NodeClient.sendEvent\n (node_modules/.pnpm/@sentry+core@10.56.0/node_modules/@sentry/core/src/client.ts:557:15)\n```\n\n#### `next build`\n\nBoth routes fail to prerender:\n\n```\nError: Route \"/[id]\" used `crypto.randomUUID()` before accessing either uncached data\n(e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and\n`searchParams`). Accessing random cryptographic values synchronously in a Server Component\nrequires reading one of these data sources first. Alternatively, consider moving this\nexpression into a Client Component or Cache Component.\nSee more info here: https://nextjs.org/docs/messages/next-prerender-crypto\n\n at d (app/[id]/page.tsx:18:3)\n 16 | const { id } = await params;\n 17 | if (id === \"exception\") {\n> 18 | Sentry.captureException(new Error(\"Test error\"));\n | ^\n 19 | return `Error captured for id exception`;\n 20 | }\n\nError occurred prerendering page \"/exception\". Read more: https://nextjs.org/docs/messages/prerender-error\nExport encountered an error on /[id]/page: /exception, exiting the build.\n⨯ Next.js build worker exited with code: 1 and signal: null\n```\n\n### Deployed to Vercel\n\nWhen deploying our production app to Vercel, I'm seeing the same `new Date()` violation at **runtime**, during page (re)generation:\n\n```\nError: Route \"...\" used `new Date()` before accessing either uncached data (e.g. `fetch()`) or Request data (e.g. `cookies()`, `headers()`, `connection()`, and `searchParams`). Accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-current-time\n at n.createSessionEnvelope (.next/server/chunks/_0han8ax._.js:7:1154)\n at c.sendSession (.next/server/chunks/_0han8ax._.js:8:48560)\n at c.captureSession (.next/server/chunks/_0han8ax._.js:8:46952)\n at c._updateSessionFromEvent (.next/server/chunks/_0han8ax._.js:8:49736)\n at \u003cunknown> (.next/server/chunks/_0han8ax._.js:8:52764)\n```\n\nI can't reliably reproduce it in isolation, but it looks like it's the same root cause as the reproduction dev/build errors.\n\n### Additional Context\n\nI already posted about this in https://github.com/getsentry/sentry-javascript/issues/17895#issuecomment-3660151361. The reply suggested not calling it during prerendering, but that doesn't really help me for the **runtime** case I observed in our production app (cc @chargome).\n\nJust to reiterate, the `next build` failure is a secondary concern for me because it only happens in the reproduction, but it seems to be caused by the same underlying incompatibility, so fixing one will likely fix the other.\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>","author":{"url":"https://github.com/qnten","@type":"Person","name":"qnten"},"datePublished":"2026-06-03T15:54:26Z","url":"https://github.com/getsentry/sentry-javascript/issues/21333"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8b9374a3-3953-e65a-4c71-dfa1a5a45ed4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D926:22033E:4B274:64596:6B042AAB |
| html-safe-nonce | 597a2e38f43b54b59b147a86cfcbecc90ba76401425b7d365b77516993bfb800 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTI2OjIyMDMzRTo0QjI3NDo2NDU5Njo2QjA0MkFBQiIsInZpc2l0b3JfaWQiOiI0MjE0OTUwODQ1ODkwMTc3NzA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ac2291af3dc9ea286a7a5bb537d031df19393c591624b09b9331b914028fbf66 |
| hovercard-subject-tag | issue:4581480629 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/21333/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad275fd1b4f91176c322d34842754ab3486902b4392d28db1e144e217d43073c/getsentry/sentry-javascript/issues/21333 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad275fd1b4f91176c322d34842754ab3486902b4392d28db1e144e217d43073c/getsentry/sentry-javascript/issues/21333 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | qnten |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width