Repository navigation
@sentry/core is marked as being side effect free but it is not #16846
Description
Activity
export const timestampInSeconds = createUnixTimestampInSecondsFunc();Is that considered a side effect? 🤔 this exports a function, which I would have expected to be OK...?
Unfortunately Rollup it's that clever. It considers any execution that occurs from only importing a file as a side-effect.
It even detects this as a side effect:
sentry-javascript/packages/core/src/tracing/errors.ts
Lines 41 to 43 in ceb003c
// The function name will be lost when bundling but we need to be able to identify this listener later to maintain the // node.js default exit behaviour errorCallback.tag = 'sentry_tracingErrorCallback'; That can be fixed quite easily by moving the callback definition inside
registerSpanErrorInstrumentation.Rollup has an
experimentalLogSideEffectsoption which we could enable to highlight issues. We could also usetreeshake.moduleSideEffectsto tell Rollup we don't have any side effects, or to disable it for specific files we know to be safe.hmm, that setting
experimentalLogSideEffectsseems a bit overly strict. it also flags e.g.debug-build.tswhich isexport const DEBUG_BUILD = __DEBUG_BUILD__;😅How would we use
treeshake.moduleSideEffects? 🤔experimentalLogSideEffectsseems safe to use because I think it just logs when it finds side-effects.If you set
treeshake.moduleSideEffects: falseRollup assumes there are no side effects anywhere. Probably not always safe but if the tests are all great and pass then it's probably ok.You can also set it as a callback and override Rollups side-effect detection on a per-module basis.
I think I have opened PRs for all side effects in core, except for debug-build... no idea how to get rid of the warning there, this seems fine to me 😅
declare const __DEBUG_BUILD__: boolean; /** * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code. * * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking. */ export const DEBUG_BUILD = __DEBUG_BUILD__;
- added a commit that references this issue
on Jul 11, 2025 except for debug-build... no idea how to get rid of the warning there
I think its because the side-effect analysis happens before the define plugin runs so it looks like
DEBUG_BUILDis being set from a__DEBUG_BUILD__global.We might be able to use
treeshake.moduleSideEffectsto override side-effects for all./debug-build.tsfiles. I'll check it out- added 2 commits that reference this issue
on Jul 11, 2025 - added 4 commits that reference this issue
on Jul 14, 2025 - added a commit that references this issue
on Jul 15, 2025
Description
sentry-javascript/packages/core/package.json
Line 65 in b746c23
Our build output contains imports where Rollup detects side effects:

But
time.tsis the most obvious place:sentry-javascript/packages/core/src/utils/time.ts
Line 67 in b746c23
Our current build output gives warning with Cloudflare's Wranger: