Title: [nextjs] webpack keeps debug log code when `excludeDebugStatements` is set · Issue #25266 · getsentry/sentry-javascript · GitHub
Open Graph Title: [nextjs] webpack keeps debug log code when `excludeDebugStatements` is set · Issue #25266 · getsentry/sentry-javascript
X Title: [nextjs] webpack keeps debug log code when `excludeDebugStatements` is set · Issue #25266 · getsentry/sentry-javascript
Description: Problem In Next.js webpack builds, bundleSizeOptimizations.excludeDebugStatements (and the old webpack.treeshake.removeDebugLogging) does not remove the debug log code from the client bundle. The code cannot run, but it stays in the bund...
Open Graph Description: Problem In Next.js webpack builds, bundleSizeOptimizations.excludeDebugStatements (and the old webpack.treeshake.removeDebugLogging) does not remove the debug log code from the client bundle. The c...
X Description: Problem In Next.js webpack builds, bundleSizeOptimizations.excludeDebugStatements (and the old webpack.treeshake.removeDebugLogging) does not remove the debug log code from the client bundle. The c...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/25266
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[nextjs] webpack keeps debug log code when `excludeDebugStatements` is set","articleBody":"## Problem\n\nIn Next.js webpack builds, `bundleSizeOptimizations.excludeDebugStatements` (and the old `webpack.treeshake.removeDebugLogging`) does not remove the debug log code from the client bundle. The code cannot run, but it stays in the bundle and adds size. Turbopack builds remove it correctly.\n\nFound while testing getsentry/sentry-javascript#24818 on Next 15.5.27 and 16.3.6. Tracing removal works on both bundlers.\n\n## Cause\n\n* The SDK guards debug logs with `DEBUG_BUILD`, a constant exported from `@sentry/core/build/esm/debug-build.js`.\n* The define works. In the bundle, that module becomes `let n=!1`.\n* The minifier can only remove `DEBUG_BUILD && debug.log(...)` when webpack concatenates the modules into one scope. Webpack does not concatenate here. Stats give this bailout:\n `Cannot concat with ./node_modules/@sentry/core/build/esm/debug-build.js: Module ./node_modules/@sentry/nextjs/build/esm/client/index.js is referenced from different chunks by these modules: ./instrumentation-client.ts`\n* So the code reads `DEBUG_BUILD` through a getter at runtime, and the guarded code stays.\n\nThe same issue probably affects other webpack apps where the SDK is in a shared chunk, not only Next.js.\n\n## Possible fix\n\nCheck `typeof __SENTRY_DEBUG__` at each use site, so that each module gets the literal from the define and does not import a shared constant. This touches all packages, so measure the size effect on the CDN bundles too.\n\n## Repro\n\n`~/projects/experiments/nextjs-turbopack-define-booleans` (ask @andrei.borza). Build with `next build --webpack` and `bundleSizeOptimizations: { excludeDebugStatements: true }`, then search the client chunks for `Integration installed`.","author":{"url":"https://github.com/andreiborza","@type":"Person","name":"andreiborza"},"datePublished":"2026-10-12T11:06:58Z","url":"https://github.com/getsentry/sentry-javascript/issues/25266"}
| 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:47a88af1-6ec4-6047-6d71-233ab4fd939b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E1A2:27BDC8:245BA3:320542:6B044AF9 |
| html-safe-nonce | d2009b87b2958b27cbbe923e9ead2e183e4577672abb0559e6478f1d7789da1b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMUEyOjI3QkRDODoyNDVCQTM6MzIwNTQyOjZCMDQ0QUY5IiwidmlzaXRvcl9pZCI6IjYxMjgyNzEwOTg3OTU4MDU0MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3992c1cc931d85045c78ad2727e3a65ce3265f4a969243e24ac29c618c69cb35 |
| hovercard-subject-tag | issue:5812665633 |
| 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/25266/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2141876f20a902d77e2935433dd38eece0ed42f2b0b2e5bfd15cb9bc90c85aac/getsentry/sentry-javascript/issues/25266 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2141876f20a902d77e2935433dd38eece0ed42f2b0b2e5bfd15cb9bc90c85aac/getsentry/sentry-javascript/issues/25266 |
| og:image:alt | Problem In Next.js webpack builds, bundleSizeOptimizations.excludeDebugStatements (and the old webpack.treeshake.removeDebugLogging) does not remove the debug log code from the client bundle. The c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andreiborza |
| hostname | github.com |
| expected-hostname | github.com |
| None | 002aa6b95ffa730b0aec436a5c383f536ad677284e60056037fb120afe37b730 |
| 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 | 059f24c781e3a0d7df3f27a97da0e93fab06ae39 |
| 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