ref(nextjs)!: Move withSentryConfig to @sentry/nextjs/config - #23628
Conversation
|
bugbot run |
3b7c41d to
6c1ba7f
Compare
There was a problem hiding this comment.
✅ 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.
size-limit report 📦
|
6c1ba7f to
42429a0
Compare
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>
42429a0 to
2499913
Compare
| // 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'], |
There was a problem hiding this comment.
q: why do we need the ending now?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
q: why do we no longer need the shims here?
There was a problem hiding this comment.
Because it's not exported anymore from the runtime subpath
Moves
withSentryConfigandSentryBuildOptionsto a new@sentry/nextjs/configentry point, separating build-time code from the SDK runtime. This matches the other framework SDKs, which expose their build plugins on./vite,./moduleand./middlewarerather than the main entry../configresolves to CommonJS under both conditions, sincenext.config.mjsis 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.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
nodeexport 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, andcacheComponentsprerendering rejects thecrypto.randomUUID()insidecaptureException.Refs #22791