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
@sentry/core is marked as being side effect free but it is not #16846
Our current build output gives warning with Cloudflare's Wranger:
▲ [WARNING] Ignoring this import because "../../../../packages/core/build/esm/utils/time.js" was marked as having no side effects [ignored-bare-import]
../../../../packages/core/build/esm/trpc.js:8:7:
8 │ import './utils/time.js';
╵ ~~~~~~~~~~~~~~~~~
"sideEffects" is false in the enclosing "package.json" file:
../../../../packages/core/build/esm/package.json:1:36:
1 │ {"type":"module","version":"9.35.0","sideEffects":false}
╵ ~~~~~~~~~~~~~
// 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 experimentalLogSideEffects option which we could enable to highlight issues. We could also use treeshake.moduleSideEffects to tell Rollup we don't have any side effects, or to disable it for specific files we know to be safe.
hmm, that setting experimentalLogSideEffects seems a bit overly strict. it also flags e.g. debug-build.ts which is export const DEBUG_BUILD = __DEBUG_BUILD__; 😅
experimentalLogSideEffects seems safe to use because I think it just logs when it finds side-effects.
If you set treeshake.moduleSideEffects: false Rollup 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 😅
declareconst__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. */exportconstDEBUG_BUILD=__DEBUG_BUILD__;
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_BUILD is being set from a __DEBUG_BUILD__ global.
We might be able to use treeshake.moduleSideEffects to override side-effects for all ./debug-build.ts files. I'll check it out
Activity
mydea commentedon Jul 10, 2025
Is that considered a side effect? 🤔 this exports a function, which I would have expected to be OK...?
timfish commentedon Jul 10, 2025
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
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.mydea commentedon Jul 10, 2025
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? 🤔timfish commentedon Jul 10, 2025
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.
ref(core): Avoid side-effect of & streamline `timestampInSeconds` met…
ref(core): Avoid keeping span-FF map on GLOBAL_OBJ
ref: Avoid `enum` usage (#16922)
ref(core): Avoid keeping span-FF map on GLOBAL_OBJ
mydea commentedon Jul 11, 2025
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 😅
ref(core): Avoid keeping span-FF map on GLOBAL_OBJ
timfish commentedon Jul 11, 2025
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 outbuild: Disable side-effects for any `./debug-build.ts` file (#16929)
fix(core): Remove side-effect from `tracing/errors.ts` (#16888)
ref(core): Avoid side-effect of `vercelAiEventProcessor` (#16925)
ref(core): Keep client-logger map on carrier & avoid side-effect (#16923
ref(core): Avoid keeping span-FF map on GLOBAL_OBJ
ref(core): Avoid keeping span-FF map on GLOBAL_OBJ (#16924)
ref(core): Avoid keeping span-FF map on GLOBAL_OBJ (#16924)