indutny / webpack-common-shake

CommonJS Tree Shaker plugin for WebPack
918 stars 13 forks source link

Ignore harmony imports with redirectId #29

Closed jkrems closed 6 years ago

jkrems commented 6 years ago

The webpack 4 release of the plugin didn't properly handle some advanced cases (and who knows, maybe also some simpler ones I just haven't found yet). Specifically it broke when it encountered side-effect free ES6 modules that could be removed from the module graph entirely.

Original Description

This is more a bug report than a solution. For some reason in some situations (observed in a bigger app using apollo-client), module.mergeFrom is called for unresolved modules that have already been cleared. This triggers the unhelpful error ".forEach isn't a function" when it hits unresolved.uses.forEach.

So far I have no real reproduction and I'm not sure yet what could trigger this scenario.

jkrems commented 6 years ago

Looks like this behavior is triggered by a fun back and forth between imports, combined with "sideEffects": false in a package.json. The pure-pkg directory is a simplified version of apollo-utilities.

jkrems commented 6 years ago

Tested against an internal app. Assets are now building and the test suite passes.