Skip to content

ref(nextjs)!: Move withSentryConfig to @sentry/nextjs/config - #23628

Merged
chargome merged 1 commit into
developfrom
feat/nextjs-config-subexport
Aug 26, 2026
Merged

ref(nextjs)!: Move withSentryConfig to @sentry/nextjs/config#23628
chargome merged 1 commit into
developfrom
feat/nextjs-config-subexport

Conversation

@chargome

@chargome chargome commented Aug 26, 2026

Copy link
Copy Markdown
Member

Moves withSentryConfig and SentryBuildOptions to a new @sentry/nextjs/config entry point, separating build-time code from the SDK runtime. This matches the other framework SDKs, which expose their build plugins on ./vite, ./module and ./middleware rather than the main entry.

./config resolves to CommonJS under both conditions, since next.config.mjs is loaded by a plain Node ESM loader and the build-time code resolves webpack loader and template paths with __dirname, which is not defined in an ES module. Safe because the module holds no SDK state.

// next.config.mjs
- import { withSentryConfig } from '@sentry/nextjs';
+ import { withSentryConfig } from '@sentry/nextjs/config';

Breaks every existing next.config, but at the first build. Runtime APIs untouched. Docs and the wizard need the same change.

This is a prerequisite for splitting the node export condition (#22791), left for a follow-up. Serving the ESM server build to Next breaks two things CommonJS currently hides: 87 browser-only names are missing from the server build, and cacheComponents prerendering rejects the crypto.randomUUID() inside captureException.

Refs #22791

@chargome chargome self-assigned this Aug 26, 2026
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@chargome
chargome force-pushed the feat/nextjs-config-subexport branch from 3b7c41d to 6c1ba7f Compare August 26, 2026 09:27

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3b7c41d. Configure here.

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.57 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.58 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.6 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.51 kB - -
@sentry/browser (incl. Tracing, Replay) 88.04 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.44 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.75 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.44 kB - -
@sentry/browser (incl. Feedback) 45.81 kB - -
@sentry/browser (incl. sendFeedback) 33.36 kB - -
@sentry/browser (incl. FeedbackAsync) 38.46 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.31 kB - -
@sentry/react (incl. Tracing) 50.79 kB - -
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.82 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.07 kB - -
CDN Bundle (incl. Logs, Metrics) 32.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 50.95 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 72.98 kB - -
CDN Bundle (incl. Tracing, Replay) 86.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.25 kB - -
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.69 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.38 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.36 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.12 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.79 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.48 kB - -
@sentry/nextjs (client) 53.33 kB - -
@sentry/sveltekit (client) 49.03 kB - -
@sentry/core/server 65.16 kB - -
@sentry/core/browser 52.38 kB - -
@sentry/node 121.78 kB +0.02% +21 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.22 kB - -
@sentry/node - without tracing 87.96 kB +0.03% +22 B 🔺
@sentry/aws-serverless 96.14 kB +0.03% +27 B 🔺
@sentry/cloudflare (withSentry) - minified 199.5 kB - -
@sentry/cloudflare (withSentry) 495.46 kB - -

View base workflow run

@chargome
chargome force-pushed the feat/nextjs-config-subexport branch from 6c1ba7f to 42429a0 Compare August 26, 2026 11:52
Separate build-time config from the SDK runtime by giving `withSentryConfig`
and `SentryBuildOptions` their own entry point, matching the other framework
SDKs, which expose their build plugins on `./vite`, `./module` and
`./middleware` rather than the main entry.

`./config` resolves to CommonJS under both conditions, since `next.config.mjs`
is loaded by a plain Node ESM loader and the build-time code resolves webpack
loader and template paths with `__dirname`, which is not defined in an ES
module. This is safe because the module holds no SDK state.

Drop the no-op `withSentryConfig` passthroughs from the client and edge builds:
they only existed so the name stayed resolvable when Next compiled a module that
imported it for those runtimes, which cannot happen now.

Add the `.js` extension to the `next/constants` import so the ESM server build
is loadable under a plain Node loader, and guard that with a test — Node does no
extension resolution for ESM.

This is a prerequisite for splitting the `node` export condition into
`import`/`require` (#22791), which is left for a follow-up: serving the ESM
server build to Next turns two latent problems into build failures, since
turbopack can then statically analyse it. Browser-only names that client
components import are genuinely absent from the server build, and
`cacheComponents` prerendering rejects the `crypto.randomUUID()` inside
`captureException`. Both are masked today by CommonJS being opaque.

BREAKING CHANGE: `withSentryConfig` and `SentryBuildOptions` are no longer
exported from `@sentry/nextjs`. Import them from `@sentry/nextjs/config`.

Refs #22791
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chargome
chargome force-pushed the feat/nextjs-config-subexport branch from 42429a0 to 2499913 Compare August 26, 2026 12:11
@chargome
chargome marked this pull request as ready for review August 26, 2026 12:24
@chargome
chargome requested a review from a team as a code owner August 26, 2026 12:24
@chargome
chargome requested review from andreiborza, nicohrubec and s1gr1d and removed request for a team August 26, 2026 12:24
// the name doesn't match an SDK dependency)
packageSpecificConfig: {
external: ['next/router', 'next/constants', 'next/headers', 'stacktrace-parser'],
external: ['next/router', 'next/constants.js', 'next/headers', 'stacktrace-parser'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: why do we need the ending now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically belongs to the part where we split the node exports into require and import (which I took out of this pr). There's no export map from nextjs and the esm import broke here, just left it as a safer default

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But currently this does not do anything on webpack/turbopack

/**
* Just a passthrough in case this is imported from the client.
*/
export function withSentryConfig<T>(exportedUserNextConfig: T): T {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: why do we no longer need the shims here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's not exported anymore from the runtime subpath

@chargome
chargome merged commit c9211d8 into develop Aug 26, 2026
78 checks passed
@chargome
chargome deleted the feat/nextjs-config-subexport branch August 26, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants