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

multiple inputs leading to full third party package imports #3109

Closed
JoviDeCroock opened this issue Sep 11, 2019 · 5 comments
Closed

multiple inputs leading to full third party package imports #3109

JoviDeCroock opened this issue Sep 11, 2019 · 5 comments

Comments

@JoviDeCroock
Copy link
Contributor

JoviDeCroock commented Sep 11, 2019

  • Rollup Version: 1.20.2
  • Operating System (or Browser): MacOS Mojave 10.14.6
  • Node Version: 10.16.0

How Do We Reproduce?

Reproduction

Note how graphql goes from a tree-shakeable import to a "polyfill" one. The behavior in the actual repo is a bit more complicated since the import has to stay in the shared folder because it's used there. I can always supply more if needed, wanted to start out by having the most minimal reproduction.

I have linked the PR where the issue persists to this one, in that branch when you do:

yarn && yarn build

move to the /dist/esm folder and you'll see in core.js and urql.js that the full graphql and fast-json-stable-stringify are imported but only used in the shared index file.

Note that we are using

  treeshake: {
    moduleSideEffects: false,
    propertyReadSideEffects: false,
  }

And the graphql module itself has sideEffects: false

Expected Behavior

I would expect the graphql import to be cut away in both entries and to only live in the shared if used there.

Actual Behavior

The imports stay and are now a huge bundle bloat.

@lukastaegert
Copy link
Member

Any import can have a side-effect, no matter if you actually import any bindings. Even if the bindings are removed, there could still be side-effects. Use the moduleSideEffects to give hints about external dependencies if you need to. Otherwise what you see is the correct behaviour.

@JoviDeCroock
Copy link
Contributor Author

JoviDeCroock commented Sep 11, 2019

@lukastaegert shouldn't treeshake: { moduleSideEffects: false } be the behavior you are describing? Even with

moduleSideEffects: (_, external) => {
  return !Boolean(external);
},

I see the empty modules pop up

@lukastaegert
Copy link
Member

Ah, sorry. This is a known "issue", in a way. So your file is not external but internal, so your REPL is not really accurate. This would be a more accurate example:

https://rollupjs.org/repl/?version=1.21.2&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMEtpbmQlMjAlN0QlMjBmcm9tJTIwJy4lMkZncmFwaHFsJyUzQiU1Q25jb25zb2xlLmxvZyglMjBLaW5kJTIwKSUzQiUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTJDJTdCJTIybmFtZSUyMiUzQSUyMm90aGVyRW50cnkuanMlMjIlMkMlMjJjb2RlJTIyJTNBJTIyaW1wb3J0JTIwJTdCJTIwS2luZCUyMCU3RCUyMGZyb20lMjAnLiUyRmdyYXBocWwnJTNCJTVDbmNvbnNvbGUubG9nKDEpJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyZ3JhcGhxbC5qcyUyMiUyQyUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjBjb25zdCUyMEtpbmQlMjAlM0QlMjAzJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzbSUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

What is happening here is that Rollup assumes that any file that is not completely removed does have side-effects of some kind and ignores the moduleSideEffects flag in that case. We are considering to change this and I believe there might be an older issue relating to this but until now, this has not yet been addressed.

So yes, we hope to evetually change the logic such that when a file

  • is included for some reason
  • does have moduleSideEffects: false
  • is imported without bindings by some file,

then that import should be suppressed.

@lukastaegert
Copy link
Member

This will be fixed by #3369

@lukastaegert
Copy link
Member

Solved in rollup@2.0.0

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

2 participants