evanw / esbuild

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

Tree shaking doesn't remove the unused variable #2517

Open lvqq opened 2 years ago

lvqq commented 2 years ago

For example, the source code as like:

const cwd = process.cwd();

export {}

Will be minified to:

var c=process.cwd();

The variable c is unused but not removed by tree shaking.

And output from webpack's or rollup's tree shaking gets process.cwd() , it doesn't include the unused var

hyrious commented 2 years ago

I guess #1794 should be the same thing where an unused variable name (either from import another file or just var a = side_effect()) not being removed.

I want to mention #1747 too as all 3 issues here are asking esbuild to do extra work after (or within?) the linking step.

sanderkoenders commented 1 year ago

I would like to thumb up this issue as we are also having issues with this. It is even including unused dev dependencies in our production build causing runtime failures because dev dependencies are not installed in our production environment.