privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.58k stars 106 forks source link

reference errors on build instead of hoisting #353

Closed Joshuajrodrigues closed 9 months ago

Joshuajrodrigues commented 9 months ago

Problem

Firstly thanks for making this, you reduced my build time by 50 percent!

I'm getting reference errors in some of my project files. These are easily fixed by just moving the initialization on top. But Babel doesn't throw these errors. I tried goggling to see if this is esbuild related topic but didn't really get a clear explanation. Closes I got to was to do with eval.

Some of the code in my react app looks like this

` Let x = stateVar

Const [stateVar, setStateVar]= useState(0) ` Can be easily fixed but it'sa chore and I have inherited this project so I have no clue why it's this way.

The error is Can't acess lexical l in case of example when I run node dist/main.js in stackblitz reproduction

Expected behavior

Hoist the variables

Minimal reproduction URL

https://stackblitz.com/edit/node-lja1pf?file=src%2Findex.js,dist%2Fmain.js&view=editor

Version

latest

Node.js version

16 or 18 also

Package manager

npm

Operating system

Windows

Contributions

privatenumber commented 9 months ago

Seems like the issue you're facing isn't related to esbuild or esbuild-loader.

The bug resides within your code, and you're looking for an automated fix, but looks like you're looking in the wrong place.

Consider exploring an ESLint solution, as it could help address the problem more effectively.