Rollup 4.x sideEffects: false package declaration vs unannotated module side effects
0 reputation · 03 Mar 2023, 06:23 UTC
0 reputation · 03 Mar 2023, 06:23 UTC
Rollup 4.x treats "sideEffects": false in package.json as a strong signal to eliminate unused exports, yet individual modules may contain top-level statements (such as console.log or mutation of global state) that are not annotated with /* @__PURE__ */. The bundler must decide whether to trust the package-level declaration or require per-module purity annotations.
Version 4 tightened side-effect detection for re-exported namespace objects, potentially breaking builds that relied on looser elimination in 3.x. The webpack-style array syntax "sideEffects": ["*.css"] is ignored; only boolean false is recognized. Monorepo setups with hoisted node_modules may cause Rollup to read package.json from an unexpected location, altering side-effect assumptions. The treeshake.moduleSideEffects option ("no-external" | "if-removed" | false) changes whether external dependencies are considered side-effect-free, with "if-removed" as the default.
Source maps do not record which modules were eliminated, making post-build verification indirect. Watch mode reuses the module graph from the previous build; if package.json sideEffects changes between runs, the cached graph may retain stale assumptions until a full restart.
Does Rollup 4.x prioritize the package.json boolean over top-level statements in individual modules when both are present? How does the treeshake.moduleSideEffects option interact with a dependency that declares sideEffects: false but contains unannotated side effects? What verification approach reliably confirms which modules were eliminated without relying on source maps?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.