Skip to content

fix(nextjs): Resolve Next.js version relative to the SDK when cwd differs - #24462

Merged
chargome merged 1 commit into
developfrom
investigate-issue-24461
Sep 17, 2026
Merged

chargome merged 1 commit into
developfrom
investigate-issue-24461

Conversation

@chargome

Copy link
Copy Markdown
Member

withSentryConfig detected the Next.js version by resolving next/package.json from process.cwd() only. When the process starts outside the Next.js project root (custom servers, monorepos started from the repo root, supervisors with their own cwd), detection returns undefined and the SDK silently falls back to the Next 14 config shape. On Next 15+ this means serverExternalPackages is never set, and Next warns about the unrecognized experimental keys.

Resolution now still tries process.cwd() first, so the project's own next wins in the normal case, and falls back to resolving from the SDK's own location. next is a peer dependency, so it's reachable from there even under pnpm's isolated installs.

Fixes #24461

…fers

Next.js version detection only resolved `next/package.json` from `process.cwd()`.
When the process starts outside the Next.js project root (custom servers, monorepos),
detection returned undefined and `withSentryConfig` fell back to the Next 14 config
shape, silently dropping `serverExternalPackages` on Next 15+.

Fall back to resolving from the SDK's own location, where `next` is reachable as a
peer dependency.

Fixes #24461
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chargome chargome self-assigned this Sep 17, 2026
@chargome
chargome requested a review from JPeer264 September 17, 2026 12:53
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@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 dec3e31. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.09 kB - -
@sentry/browser - with treeshaking flags 27.35 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.26 kB - -
@sentry/browser (incl. Tracing) 50.6 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 50.62 kB - -
@sentry/browser (incl. Tracing, Profiling) 53.61 kB - -
@sentry/browser (incl. Tracing, Replay) 90.15 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.25 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 94.85 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 107.83 kB - -
@sentry/browser (incl. Feedback) 46.62 kB - -
@sentry/browser (incl. sendFeedback) 34.15 kB - -
@sentry/browser (incl. FeedbackAsync) 39.26 kB - -
@sentry/browser (incl. Metrics) 30.1 kB - -
@sentry/browser (incl. Logs) 30.35 kB - -
@sentry/browser (incl. Metrics & Logs) 31.02 kB - -
@sentry/react 30.84 kB - -
@sentry/react (incl. Tracing) 52.94 kB - -
@sentry/vue 36.34 kB - -
@sentry/vue (incl. Tracing) 52.91 kB - -
@sentry/svelte 29.11 kB - -
CDN Bundle 30.8 kB - -
CDN Bundle (incl. Tracing) 51.15 kB - -
CDN Bundle (incl. Logs, Metrics) 33.06 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.14 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.75 kB - -
CDN Bundle (incl. Tracing, Replay) 88.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 94.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.78 kB - -
CDN Bundle - uncompressed 91.16 kB - -
CDN Bundle (incl. Tracing) - uncompressed 152.66 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.73 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 158.61 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.14 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 272.23 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 278.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 285.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 291.86 kB - -
@sentry/nextjs (client) 55.27 kB - -
@sentry/sveltekit (client) 51.05 kB - -
@sentry/core/server 39.63 kB - -
@sentry/core/browser 13.66 kB - -
@sentry/node 132.37 kB +0.02% +18 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.03 kB - -
@sentry/node - without tracing 89.82 kB +0.04% +30 B 🔺
@sentry/node - without channel injection 111.23 kB +0.02% +20 B 🔺
@sentry/aws-serverless 98.06 kB +0.03% +26 B 🔺
@sentry/cloudflare (withSentry) - minified 204.52 kB - -
@sentry/cloudflare (withSentry) 508.73 kB - -

View base workflow run

@chargome
chargome marked this pull request as ready for review September 17, 2026 13:06
@chargome
chargome requested a review from a team as a code owner September 17, 2026 13:06
@chargome
chargome requested review from mydea and s1gr1d and removed request for a team September 17, 2026 13:06
@chargome
chargome merged commit 08fef6d into develop Sep 17, 2026
88 checks passed
@chargome
chargome deleted the investigate-issue-24461 branch September 17, 2026 14:00
chargome added a commit that referenced this pull request Sep 18, 2026
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.

@sentry/nextjs: Next.js version detection resolves from process.cwd(), silently degrading config to Next 14 shape when cwd ≠ project root

2 participants