"export * from" breaks tree shaking
See original GitHub issueBug report
What is the current behavior? One of our dependencies re-exports the index.js file of https://www.npmjs.com/package/@material-ui/core like so:
export * from '@material-ui/core';
We would expect Webpack 5 to tree shake this as per https://webpack.js.org/blog/2020-10-10-webpack-5-release/#nested-tree-shaking, however, inspecting the build shows that the ENTIRE @material-ui/core
is included in the bundle - even if no modules from this package are used.
If the current behavior is a bug, please provide the steps to reproduce.
- Set up basic webpack project
- In a dependency in node_modules, re-export
@material-ui/core
as per the above - Create production build
- Inspect generated chunks
What is the expected behavior?
Webpack should deep-shake the re-exported package.
Other relevant information: webpack version: 5.40.0 Node.js version: 14 Operating System: OSX Catalina Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Tree shaking and code splitting in webpack - LogRocket Blog
Modules that are side effects cannot be tree shaken because they don't have imports and exports.
Read more >Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >Is re-exporting modules harmful for tree-shaking?
It is believed that export * from may harm webpack's tree-shaking capabilities, by tricking it into believing an export is used when it...
Read more >bug report - GitHub
It seems Parcel2 breaks tree-shaking ability when export * from … is used. This used to work for us with Parcel1, all we've...
Read more >JavaScript tree shaking, like a pro | by Daniel Brain
The principle behind tree shaking is as follows: You declare all of your imports and exports for each of your modules; Your bundler...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
export *
is not related to the export-default-from proposal. Nonetheless all of these constructs are supported for tree shaking.Could you please provide a complete reproduction for the problem?
Hm, looking into it, it seems like this is non-standard syntax (still a proposal - https://github.com/tc39/proposal-export-default-from), I suppose that is the reason it does not work?