Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esbuild --bundle omits variable assignment if variable is redeclared #2099

Closed
pcattori opened this issue Mar 12, 2022 · 1 comment
Closed

Comments

@pcattori
Copy link

pcattori commented Mar 12, 2022

esbuild version: 0.14.25


example.js:

var a = 1;
var a;
console.log(a);

Running node example.js prints 1. ✅

Running esbuild example.js --bundle --outfile=build.js produces:

(() => {
  // example.js
  var a;
  console.log(a);
})();

Note the missing a = 1 assignment in build.js.
Running node build.js prints undefined, when it should print 1. ❌


For context: the React development build hosted on esm.sh (https://esm.sh/react@17.0.2?dev) includes a variable re-declaration resulting in Uncaught TypeError: _a is undefined when running the built code.

@pcattori pcattori changed the title esbuild --bundle omits variable assignment if variable is later redeclared esbuild --bundle omits variable assignment if variable is redeclared Mar 12, 2022
@pcattori pcattori changed the title esbuild --bundle omits variable assignment if variable is redeclared esbuild --bundle omits variable assignment if variable is redeclared Mar 12, 2022
@pcattori
Copy link
Author

Possible duplicate of #2080 and #2098

@evanw evanw closed this as completed in ea3b3d3 Mar 13, 2022
zhusjfaker pushed a commit to speedy-js/esbuild that referenced this issue Mar 28, 2022
hardfist pushed a commit to speedy-js/esbuild that referenced this issue Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant