Title: @sentry/nextjs: Next.js version detection resolves from process.cwd(), silently degrading config to Next 14 shape when cwd ≠ project root · Issue #24461 · getsentry/sentry-javascript · GitHub
Open Graph Title: @sentry/nextjs: Next.js version detection resolves from process.cwd(), silently degrading config to Next 14 shape when cwd ≠ project root · Issue #24461 · getsentry/sentry-javascript
X Title: @sentry/nextjs: Next.js version detection resolves from process.cwd(), silently degrading config to Next 14 shape when cwd ≠ project root · Issue #24461 · getsentry/sentry-javascript
Description: Summary withSentryConfig detects the Next.js version by resolving next/package.json from process.cwd(). When the process's cwd is not the Next.js project root, detection returns undefined and the SDK silently falls back to the Next 14 co...
Open Graph Description: Summary withSentryConfig detects the Next.js version by resolving next/package.json from process.cwd(). When the process's cwd is not the Next.js project root, detection returns undefined and the S...
X Description: Summary withSentryConfig detects the Next.js version by resolving next/package.json from process.cwd(). When the process's cwd is not the Next.js project root, detection returns undefined and t...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/24461
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@sentry/nextjs: Next.js version detection resolves from process.cwd(), silently degrading config to Next 14 shape when cwd ≠ project root","articleBody":"## Summary\n\n`withSentryConfig` detects the Next.js version by resolving `next/package.json` **from `process.cwd()`**. When the process's cwd is not the Next.js project root, detection returns `undefined` and the SDK silently falls back to the **Next 14 config shape** — emitting `experimental.instrumentationHook` and `experimental.serverComponentsExternalPackages`, and **not** emitting `serverExternalPackages`.\n\nOn Next ≥ 15 that means the server-external-packages list is written under a key Next no longer reads, so **it is silently not applied**. Next then warns about the unrecognized keys, which is the visible symptom but not the important part.\n\n## Offending line\n\n`build/cjs/config/util.js` (identical in the ESM build), present in **10.73.0, 10.74.0 and 10.75.0**:\n\n```js\nfunction resolveNextjsPackageJson() {\n try {\n return createRequire(`${process.cwd()}/`).resolve(\"next/package.json\");\n } catch {\n return void 0;\n }\n}\n```\n\nThe resolution base is the *process working directory*, not the location of the config module or the Next.js project.\n\n## Minimal reproduction\n\n`_repro.mjs`, placed in a Next.js project root:\n\n```js\nimport { withSentryConfig } from '@sentry/nextjs/config';\nconst out = withSentryConfig({}, { silent: true });\nconst cfg = typeof out === 'function' ? await out() : out;\nconsole.log('cwd :', process.cwd());\nconsole.log('experimental :', JSON.stringify(cfg.experimental ?? null));\nconsole.log('serverExternalPackages :', Array.isArray(cfg.serverExternalPackages) ? cfg.serverExternalPackages.length + ' pkgs' : 'UNSET');\n```\n\n**A — cwd is the project root:**\n\n```\n$ node ./_repro.mjs\ncwd : /path/to/frontend\nexperimental : {\"clientTraceMetadata\":[\"baggage\",\"sentry-trace\"]}\nserverExternalPackages : 22 pkgs\n```\n\n**B — identical config, cwd elsewhere** (`env -u NODE_PATH`, since `NODE_PATH` masks the bug):\n\n```\n$ cd /tmp && env -u NODE_PATH node /path/to/frontend/_repro.mjs\n[@sentry/nextjs] The Sentry SDK was not able to determine your Next.js version. …clientTraceMetadata…\n[@sentry/nextjs] The Sentry SDK was not able to determine your Next.js version. …instrumentationHook…\ncwd : /tmp\nexperimental : {\"instrumentationHook\":true,\"serverComponentsExternalPackages\":[\"amqplib\",\"connect\",…,\"tedious\"]}\nserverExternalPackages : UNSET\n```\n\nOnly `cwd` differs.\n\n## Why this is hit in practice\n\nAny setup where the Node process starts somewhere other than the Next.js project root. In our case a single Node process serves an Express API *and* Next.js: the entry file lives in `backend/`, the process starts at the repo root, and `next` is under `frontend/node_modules`. The build (`cd frontend && next build`) detects correctly; the **runtime** re-evaluation of `next.config.mjs` does not, so build-time and runtime config silently disagree.\n\nAlso affects: monorepos with a hoisted or non-root Next app, custom servers, and anything started by a supervisor with its own cwd.\n\n## Impact\n\n1. **Functional (main concern):** on Next ≥ 15 `serverExternalPackages` is never set, so the auto-instrumented server packages are not externalized. Failure is silent — no error, just a different config.\n2. **Cosmetic:** Next logs `Unrecognized key(s) in object: 'instrumentationHook', 'serverComponentsExternalPackages' at \"experimental\"`.\n3. **Misleading turbopack warning:** `…compatible with Turbopack on Next.js version 15.4.1 or later. You are currently on undefined.`\n\n## The documented workaround does not work on Next 16\n\nThe log line suggests:\n\n> To silence Next.js' warning, explicitly set the `experimental.instrumentationHook` option … to `undefined`.\n\nOn Next 16 that makes it **worse** — the key is still present on the object, so Next flags it at build time where it previously did not:\n\n```\n⚠ Invalid next.config.mjs options detected:\n⚠ Unrecognized key(s) in object: 'instrumentationHook' at \"experimental\"\n```\n\nVerified against `next@16.3.5`.\n\n## Suggested fix\n\nResolve relative to something stable rather than `process.cwd()` — the SDK module's own location (`createRequire(import.meta.url)` / `__filename`), with `process.cwd()` as a fallback. Both resolve correctly in the normal case; only the module-relative one also works when cwd differs.\n\nAn escape hatch (an explicit `nextjsVersion` option on `withSentryConfig`) would help anyone the heuristic still can't reach.\n\n## Versions\n\n| | |\n|---|---|\n| `@sentry/nextjs` | 10.73.0 / 10.74.0 / **10.75.0** (all affected) |\n| `next` | 16.3.5 |\n| node | 22.18.0 (prod), 26.8.1 (local) |","author":{"url":"https://github.com/hoornet","@type":"Person","name":"hoornet"},"datePublished":"2026-09-17T12:35:53Z","url":"https://github.com/getsentry/sentry-javascript/issues/24461"}
| 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:f7f9d485-26c4-19a9-4be9-4108046fe5fd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88FE:1E3B91:4118E5:5957B9:6B046E33 |
| html-safe-nonce | 742e83aa311ac3536c6a5c6404ec425adb85b28608840b6e3b18aebd0093e2e7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEZFOjFFM0I5MTo0MTE4RTU6NTk1N0I5OjZCMDQ2RTMzIiwidmlzaXRvcl9pZCI6IjU3NzQyNTcxNjUyOTI1NjQwMTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2d2e82dd541aa46d1bbb2fb7852b8d35f3c22c5f4f39d2e394e74e12c11155ff |
| hovercard-subject-tag | issue:5487417100 |
| 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/24461/issue_layout |
| twitter:image | https://opengraph.githubassets.com/981631283a340798752c9b72be33ee6c79ce895c77d07bd227dc12c776b837bb/getsentry/sentry-javascript/issues/24461 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/981631283a340798752c9b72be33ee6c79ce895c77d07bd227dc12c776b837bb/getsentry/sentry-javascript/issues/24461 |
| og:image:alt | Summary withSentryConfig detects the Next.js version by resolving next/package.json from process.cwd(). When the process's cwd is not the Next.js project root, detection returns undefined and the S... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hoornet |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| 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 | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| 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