evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.19k stars 1.15k forks source link

esbuild doesn't remove unused imports from external modules #1794

Open egoist opened 2 years ago

egoist commented 2 years ago

Tested against:

export { useRoute } from "vue-router"

The command I ran:

esbuild index.js --bundle --outfile=out.js --external:vue --format=esm

Result, unused imports from vue:

CleanShot 2021-11-22 at 21 33 08@2x

Online playground:

https://stackblitz.com/edit/node-fm1edb?file=readme.md

cyan-2048 commented 2 years ago

same problem here...

// helper.js
import scrollIntoView from "scroll-into-view";

export async function centerScroll(){
return scrollIntoView(/* ... */)
}

export async function delay(){
// ...
}
import {delay} from "./helper.js"
/* this causes scrollIntoView to also be in the bundle!  */
cyan-2048 commented 2 years ago

darn it! i was going to move to esbuild

hanayashiki commented 2 years ago

any updates on this?

cyan-2048 commented 2 years ago

i wish this could be fixed, esbuild is literally perfect.... except this problem, one of the reasons to use a bundler is because of the tree shaking

ghost commented 1 year ago

Any updates on this? Maybe a plugin could help?

shixish commented 1 year ago

Darn I'm seeing this as well...

jagribble commented 11 months ago

Thought I was going mad. Also seeing this when using named imports

sofienjoulak commented 10 months ago

hopefully one day....

jhaemin commented 8 months ago

Any updates? esbuild bundles everything

alexmorleyfinch commented 5 months ago

Any updates?

CodeFromAnywhere commented 1 month ago

This is a huge problem!