-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Dedupe dependencies #1038
Comments
This is more a problem with your package manager, if your package manager has duplicate dependencies esbuild will duplicate that code too If you use yarn you can use the |
Yarn has a builtin dedupe command so you can run Though it would be interesting if esbuild could detect when files are indentical and only store its content once but still preserve the dependency tree / module instance |
What esbuild is doing here appears to be correct. The file Unlike some other programming languages, a duplicate copy of code is not equivalent to the original in JavaScript. Function objects in JavaScript have their own referential identity and each copy of the library would have its own copy of its internal state. It would be incorrect for esbuild to make this transformation itself, so I'm going to close this issue as "working as intended". See also #928. Note that using You can also work around this with an on-resolve plugin: https://esbuild.github.io/plugins/#resolve-callbacks. The plugin could intercept these separate paths and map them to the same path. Then they would be considered to be the same module and be merged. |
I just ran into this too w/o anything fancy going on. Here's a reproduction, but the gist of it is that 5 source files include: import colors from 'kleur'; ...which, with esbuild, produces an output file with 5 instances of the same statement. I'm targeting My reproduction includes the output code that Rollup was producing.
Edit: Also included a |
@lukeed That sounds like an unrelated issue, and a duplicate of #475. I'm working on fixing this one. The problem in that case is not that a file is present in the bundle multiple times like this issue, since two import statements for the same path do not result in that path being imported multiple times. |
@evanw Ah sorry, thanks! Should I freeze the reproduction branch in its current state or is it of no help to you? |
I don't need it, no. It's covered by #475. |
While analyzing the bundle, I found that two of my dependencies -
rxjs
andrxfire
, both depend ontslib
. This results intslib
being included twice.Is there any way to dedupe
tslib
so that only one version is included in the final bundle?The text was updated successfully, but these errors were encountered: