You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[nextjs] webpack keeps debug log code when excludeDebugStatements is set #25266
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 bundle and adds size. Turbopack builds remove it correctly.
Found while testing #24818 on Next 15.5.27 and 16.3.6. Tracing removal works on both bundlers.
Cause
The SDK guards debug logs with DEBUG_BUILD, a constant exported from @sentry/core/build/esm/debug-build.js.
The define works. In the bundle, that module becomes let n=!1.
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: 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
So the code reads DEBUG_BUILD through a getter at runtime, and the guarded code stays.
The same issue probably affects other webpack apps where the SDK is in a shared chunk, not only Next.js.
Possible fix
Check 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.
Repro
~/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.
Activity
linear-code commentedon Oct 12, 2026
JS-3914