bug: minifier used to transpile pollutes global scope with helper methods
See original GitHub issueBug description
Hi!
I am using esbuild-loader for my project with jQuery (jQuery is an external) and bootstrap 4.
While webpack is creating chunks for dynamic imports with production build, it crates weird variable assign.
I am importing bootstrap dropdown dynamically on action. In minified chunk file it creates assing var $=Object.getOwnPropertySymbols
with global scope. Which brakes my jQuery after file being imported.
I made minification with TerserWebpackPlugin
and everything works fine.
Reproduction steps
I made repository with simple webpack config to reproduce the problem. https://github.com/Oksydan/esbuild-loader-bug
Chunk with id 3 is made from bootstrap dropdown. You can find there that var $=Object.getOwnPropertySymbols
.
Environment
- esbuild-loader version: 2.9.1
- Webpack version: 4.46.0
- Operating System: macOS Catalina 10.15.7
- Node version: 15.5.1
- Package manager (npm/yarn/pnpm) and version: npm 7.7.4
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (3 by maintainers)
Top Results From Across the Web
azu on Twitter: "見てる: "bug: minifier used to transpile pollutes ...
github.combug : minifier used to transpile pollutes global scope with helper methods · Issue #139 · privaten...Bug description Hi! I am using esbuild-loader ......
Read more >@esbuild/linux-loong64 | Yarn - Package Manager
This is the Linux LoongArch 64-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
Read more >7.10.0 Released: Class Fields in preset-env, '#private in ...
By using @babel/plugin-transform-runtime , Babel will inject ponyfills (which are "pure" and don't pollute the global scope) for every used ...
Read more >CoffeeScript
If you plan to use the --transpile option (see Transpilation) you will need to also install @babel/core either globally or locally, depending on...
Read more >rollup.js
js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good news, I found a simple workaround! Using
wraps ESBuild’s helpers in an IIFE to prevent these global variable conflicts. I personally would vouch for this to be the default, as it is ESBuild’s default format when bundling for the web, but will leave that decision to the maintainers.
I was finally able to reproduce this.
This happens in situations where the minifier is used to transpile instead of the loader. The helpers are injected top-level outside of the module closures.
In this example, two output chunks declare the same variable
d
to the global scope:Input
webpack.config.js
src/a.js
src/b.js
Output
main.js
85.js
326.js