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

Removing empty imports of modules with moduleSideEffects: false #3057

Closed
stropho opened this issue Aug 13, 2019 · 5 comments
Closed

Removing empty imports of modules with moduleSideEffects: false #3057

stropho opened this issue Aug 13, 2019 · 5 comments

Comments

@stropho
Copy link

stropho commented Aug 13, 2019

  • Rollup Version: 1.19.4
  • Operating System (or Browser): Linux, Mac
  • Node Version: 10

How Do We Reproduce?

I'm not sure if this is a bug or feature request. See the example REPL

There is an import of external module
import { tool } from 'some-private-module';
in code (a shared chunk) shared across multiple entry points.
Now the entry points contain
import 'some-private-module';

In our codebase, we created a rollup plugin with a resolveId hook which resolves our 'some-private-module' as

  {
      id: '...some id...',
      external: true,
      moduleSideEffects: false, // tried but didn't help
}

Correct me if I'm wrong, but I don't see a good reason why import 'some-private-module'; exists in the entry points.

Expected Behavior

no import 'some-private-module'; in entry points

Actual Behavior

import 'some-private-module'; in entry points exist

@lukastaegert
Copy link
Member

The moduleSideEffects: false logic only prevents external imports from being included if no module in the graph actually uses something that is imported. As soon as there is a single module in the graph that uses the external import, all other imports from this module are included as well, albeit maybe as "empty" imports, which is what you witnessed.

Suppressing those imports would indeed be a non-trivial feature request as the current implementation just works via changing the side-effect detection algorithm, but "being used" is always considered a side-effect.

@lukastaegert
Copy link
Member

It could be argued, though, that for external imports the problem is a little simpler as we could run an additional check prior to finalization that filters out side-effect-free empty external imports.

@stropho
Copy link
Author

stropho commented Aug 16, 2019

Wow that was a swift response.
Well we figured out some workaround.
Anyway, let me know @lukastaegert if that additional check is something that could be considered and implemented.
Closing the issue for now

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants