ESBuild imports the entire JS file when it shouldn't

I just noticed that my Javascript bundles were unnecessarily large, so I started inspecting and I found that the named imports were not behaving as expected.

For example, doing:

import {Modal} from "bootstrap";

should only import the single component, but in my case, it bundling the entirety of the bootstrap package, resulting in a 200KB bundle.

If I do this instead:

import Modal from "bootstrap/src/modal"

Then I get a 40KB bundle as expected. Could you please let me know where I might be wrong and how I could fix this?

I have created a minimal reproducible example here:

Related?
https://github.com/evanw/esbuild/issues/1794

All open issues with the “suboptimal-output” label:
https://github.com/evanw/esbuild/issues?q=is%3Aissue+is%3Aopen+label%3Asuboptimal-output

1 Like

Thanks, I will open an issue on ESBuild.