Expected Behavior
Due to "sideEffects": false, the content of evil.js should not be included in the bundle:
Object.prototype.evil = "don't expect this to be here";
Actual Behavior
When commonjs() is included in plugins, the side effects are included, despite there being no require / exports or other required transformations.
Additional Information
AFAICT, this is essentially what breaks the majority of tree-shaking out there, lodash-es, @aws-sdk, etc...
This seems to be due to the injected commonjs--resolve plugin, replacing commonjs() with: { ...commonjs(), options: undefined }, which prevents this injection causes the issue to go away.
Injecting logging after said injected plugins' resolveId shows it returning each module twice, first with moduleSideEffects set to true, then set to false. Not sure why the same plugin resolveId is being called twice, with the same options even.
The upshot seems to be that the moduleSideEffects value from, e.g. @rollup/plugin-node-resolve is getting dropped by commonjs.
Expected Behavior
Due to
"sideEffects": false, the content ofevil.jsshould not be included in the bundle:Actual Behavior
When
commonjs()is included inplugins, the side effects are included, despite there being no require / exports or other required transformations.Additional Information
AFAICT, this is essentially what breaks the majority of tree-shaking out there,
lodash-es,@aws-sdk, etc...This seems to be due to the injected
commonjs--resolveplugin, replacingcommonjs()with:{ ...commonjs(), options: undefined }, which prevents this injection causes the issue to go away.Injecting logging after said injected plugins'
resolveIdshows it returning each module twice, first withmoduleSideEffectsset to true, then set to false. Not sure why the same pluginresolveIdis being called twice, with the same options even.The upshot seems to be that the
moduleSideEffectsvalue from, e.g.@rollup/plugin-node-resolveis getting dropped bycommonjs.