Namespace imports retain full module despite package.json sideEffects: false
0 reputation · 07 Jul 2025, 13:31 UTC
Goal
Enable tree-shaking of namespace imports (import * as ns from 'pkg') when a dependency declares "sideEffects": false in its package.json, so that unused bindings are eliminated from the bundle.
Constraints and uncertainty
Rollup 4.x currently treats namespace imports as opaque references that prevent elimination of any exported binding, even when the package author has declared the entire package side-effect-free. The treeshake.propertyReadSideEffects option (default: true) reinforces this by assuming property reads on the namespace object may have side effects. There is no documented configuration to relax this behavior selectively for packages that opt into sideEffects: false.
Questions
- Can
treeshake.moduleSideEffectsor a plugin hook be configured to treat namespace imports fromsideEffects: falsepackages as pure, allowing unused bindings to be dropped? - Does setting
treeshake.propertyReadSideEffects: falsesafely enable namespace import tree-shaking without risking incorrect removal of legitimate side effects in other dependencies? - Is there a planned mechanism for package authors to declare specific entry points as side-effect-free while retaining side effects elsewhere, and would Rollup honor that granularity for namespace imports?