Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export * from './some-file' in library breaks tree-shaking ability #8216

Open
benoitgrelard opened this issue Jun 15, 2022 · 4 comments
Open

Comments

@benoitgrelard
Copy link

πŸ› bug report

It seems Parcel2 breaks tree-shaking ability when export * from … is used.
This used to work for us with Parcel1, all we've done is upgraded to Parcel2.

πŸŽ› Configuration (.babelrc, package.json, cli command)

No special config, all stock straight out of parcel2

πŸ€” Expected Behavior

I would expect that using export * from, the exports would still be statically analysable because all these types of exports in ESM are static.

😯 Current Behavior

It breaks tree-shaking and all the members of the modules are included, even unused ones.

πŸ’ Possible Solution

I wonder if it's because Parcel now operates at the string level, rather than AST, and therefore it cannot "see" what's exported from the file when we do export * from ….

πŸ”¦ Context

This has broken tree-shaking in https://github.com/radix-ui/primitives since we moved to parcel2.

πŸ’» Code Sample

I've narrowed this down to its most basic form and made a video of it.
Don't forget to turn the sound πŸ”Š on as I explain the situation:

CleanShot.2022-06-15.at.14.22.40-converted.2.mp4

To summarize, if top-level library file is:

export { add, multiply } from "./number";

Then the module output for it looks like this:

function $2166fc5bbb34ad18$export$e16d8520af44a096(a, b) {
    return a + b;
}
function $2166fc5bbb34ad18$export$2060d2db72cce88f(a, b) {
    return a * b;
}

export {$2166fc5bbb34ad18$export$e16d8520af44a096 as add, $2166fc5bbb34ad18$export$2060d2db72cce88f as multiply};

however

If the top-level library file is:

export * from "./number";

Then the module output for it looks like this:

function $parcel$export(e, n, v, s) {
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
var `$2166fc5bbb34ad18$exports` = {};

$parcel$export($2166fc5bbb34ad18$exports, "add", () => $2166fc5bbb34ad18$export$e16d8520af44a096);
$parcel$export($2166fc5bbb34ad18$exports, "multiply", () => $2166fc5bbb34ad18$export$2060d2db72cce88f);
function $2166fc5bbb34ad18$export$e16d8520af44a096(a, b) {
    return a + b;
}
function $2166fc5bbb34ad18$export$2060d2db72cce88f(a, b) {
    return a * b;
}

export {$2166fc5bbb34ad18$export$e16d8520af44a096 as add, $2166fc5bbb34ad18$export$2060d2db72cce88f as multiply};

🌍 Your Environment

Software Version(s)
Parcel 2.6.0
Node
npm/Yarn
Operating System
@devongovett
Copy link
Member

Reproduction

@devongovett
Copy link
Member

devongovett commented Jun 18, 2022

Investigated a little but can't spend more time on it right now.

Screen Shot 2022-06-18 at 12 15 30 PM

The re-exported asset has its usedSymbols set to '*' here. The packager checks that here to determine whether to add the namespace object. I guess perhaps symbol propagation should expand the '*' symbol to the actual symbols in usedSymbols for re-exports. I tried to do this but failed some tests. Symbol propagation code is quite complex, so might need some help.

@greevz
Copy link

greevz commented Aug 3, 2022

This is also affecting us. I've recently migrated over to Parcel from Webpack, and noticed our bundle sizes were double the size because of this exact issue.

paularmstrong added a commit to paularmstrong/reui that referenced this issue Sep 11, 2022
@stoompa
Copy link

stoompa commented Mar 3, 2023

Is someone working on this? Is there a workaround? I am experiencing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants