[nextjs] webpack keeps debug log code when `excludeDebugStatements` is set

Aperta
#25,266 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
next.js, typescript, webpack

Direzione di ricerca

Start with the DEBUG_BUILD export in @sentry/core/build/esm/debug-build.js and the client entry point @sentry/nextjs/build/esm/client/index.js; reproduce with the provided experiment using next build --webpack and excludeDebugStatements: true. Check the webpack stats bailout and search client chunks for Integration installed. Done means debug log code is removed from webpack client bundles, with CDN bundle size effects measured across packages.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 bundle and adds size. Turbopack builds remove it correctly.

Found while testing getsentry/sentry-javascript#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.

Lingua principale
TypeScript
Stelle
8.8k
Fork
1.9k
Merge medio
1g 8h
PR unite (30g)
744

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry-javascript

Tutte le issue di getsentry/sentry-javascript

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.