Skip to content

esbuild is again polluting the global scope with minified variables since 0.25.9. #4297

@matths

Description

@matths

I am still working on a small reproduction setup, meanwhile I want to report this bug we encounter since version 0.25.9

We are using esbuild only indirect when building multiple Custom elements using Svelte 5.
Svelte uses Vite, Vite uses Esbuild.

So far I can share the start of some minified result of some simple Button component:

With esbuild 0.25.9 it reads like this:

var Jo=Object.defineProperty;var pi=x=>{throw TypeError(x)};var Zo=(x,q,E)=>q in x?Jo(x,q,{enumerable:!0,configurable:!0,writable:!0,value:E}):x[q]=E;var D=(x,q,E)=>Zo(x,typeof q!="symbol"?q+"":q,E),rl=(x,q,E)=>q.has(x)||pi("Cannot "+E);var a=(x,q,E)=>(rl(x,q,"read from private field"),E?E.call(x):q.get(x)),p=(x,q,E)=>q.has(x)?pi("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(x):q.set(x,E),v=(x,q,E,xt)=>(rl(x,q,"write to private field"),xt?xt.call(x,E):q.set(x,E),E),N=(x,q,E)=>(rl(x,q,"access private method"),E);
var button=(function(){"use strict";
var wi,Qe

With esbuild 0.25.8 it reads like this:

var button=function(){"use strict";
var Jo=Object.defineProperty;var pi=x=>{throw TypeError(x)};var Zo=(x,q,E)=>q in x?Jo(x,q,{enumerable:!0,configurable:!0,writable:!0,value:E}):x[q]=E;var D=(x,q,E)=>Zo(x,typeof q!="symbol"?q+"":q,E),rl=(x,q,E)=>q.has(x)||pi("Cannot "+E);var a=(x,q,E)=>(rl(x,q,"read from private field"),E?E.call(x):q.get(x)),p=(x,q,E)=>q.has(x)?pi("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(x):q.set(x,E),v=(x,q,E,xt)=>(rl(x,q,"write to private field"),xt?xt.call(x,E):q.set(x,E),E),N=(x,q,E)=>(rl(x,q,"access private method"),E);
var wi,Qe

I added line breaks to visualize where the scoping is different.
The 0.25.9 version defined a var Jo=variable and others in the global scope, and because we have multiple components at the same site we run into conflicts. So this problem might not be obvious to everyone as you need to really get into duplicate name troubles to get notice.

There are only few commits between 0.25.8 and 0.25.9, but I can't immediately see what leads to this, maybe the paranthesis handling commit, maybe something else.

I post this early, so maybe someone else did encounter something similar and can relate to this issue.

Update: So I just learned, that the stuff that is now in global scope are polyfills added by esbuild.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions