esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Tree shaking doesn't remove the unused variable

Open lvqq opened this issue 2 years ago • 1 comments

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

lvqq avatar Sep 02 '22 17:09 lvqq

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.

hyrious avatar Sep 03 '22 14:09 hyrious

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.

sanderkoenders avatar Aug 31 '23 11:08 sanderkoenders