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

@chargomechargome 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

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

Copy link
Copy Markdown
MemberAuthor

bugbot run

@chargome
chargomeforce-pushed the feat/nextjs-config-subexport branch from 3b7c41d to 6c1ba7fCompareAugust 26, 2026 09:27

@cursorcursorBot 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-actionsBot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser28.57 kB--
@sentry/browser - with treeshaking flags26.92 kB--
@sentry/browser - with treeshaking flags tracing without tracing26.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 flags77.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/react30.31 kB--
@sentry/react (incl. Tracing)50.79 kB--
@sentry/vue35.69 kB--
@sentry/vue (incl. Tracing)50.82 kB--
@sentry/svelte28.59 kB--
CDN Bundle30.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 - uncompressed89.97 kB--
CDN Bundle (incl. Tracing) - uncompressed146.69 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed96.26 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed152.38 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed225.36 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed266.12 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed271.79 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed279.81 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed285.48 kB--
@sentry/nextjs (client)53.33 kB--
@sentry/sveltekit (client)49.03 kB--
@sentry/core/server65.16 kB--
@sentry/core/browser52.38 kB--
@sentry/node121.78 kB+0.02%+21 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection)85.22 kB--
@sentry/node - without tracing87.96 kB+0.03%+22 B 🔺
@sentry/aws-serverless96.14 kB+0.03%+27 B 🔺
@sentry/cloudflare (withSentry) - minified199.5 kB--
@sentry/cloudflare (withSentry)495.46 kB--

View base workflow run

@chargome
chargomeforce-pushed the feat/nextjs-config-subexport branch from 6c1ba7f to 42429a0CompareAugust 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
chargomeforce-pushed the feat/nextjs-config-subexport branch from 42429a0 to 2499913CompareAugust 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 ownerAugust 26, 2026 12:24
@chargome
chargome requested review from andreiborza, nicohrubec and s1gr1d and removed request for a teamAugust 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
MemberAuthor

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
MemberAuthor

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
MemberAuthor

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 developAug 26, 2026
78 checks passed
@chargome
chargome deleted the feat/nextjs-config-subexport branch August 26, 2026 13:03
chargome added a commit that referenced this pull request Aug 31, 2026
Exposes `@sentry/nextjs/config` on v10 (additively) and warns once when
`withSentryConfig` is still imported from `@sentry/nextjs`, so users can
make the change on their current major and upgrade to v11 without
touching their config.
```js
// next.config.mjs
- import { withSentryConfig } from '@sentry/nextjs';
+ import { withSentryConfig } from '@sentry/nextjs/config';
```
- No build changes needed — `src/config/index.ts` was already a rollup
entrypoint, only the export map was missing. Resolves to CJS under every
condition, matching v11.
- The main entry routes through a shim so `@sentry/nextjs/config` stays
silent; `preserveModules` keeps both paths on one implementation.
- Runtime warning rather than JSDoc alone, because most `next.config.js`
files are plain JS with no TS server attached.
- `@deprecated` sits on the export site in `index.types.ts` — that's
what the `types` condition resolves to, and tagging the shim made
`no-deprecated` fire on our own re-export.
- `nextjs-16-trailing-slash` moves to a `.mjs` config on the new path —
the only format Next loads through Node's own ESM loader. The other apps
stay on the old import so the back-compat path keeps CI coverage.
Refs #23628
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for freeto 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

@chargome@nicohrubec