question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"export * from" breaks tree shaking

See original GitHub issue

Bug 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.

  1. Set up basic webpack project
  2. In a dependency in node_modules, re-export @material-ui/core as per the above
  3. Create production build
  4. 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:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
sokracommented, Jun 27, 2021

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?

2reactions
csvancommented, Jun 26, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found