You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run npm i && npx esbuild test.ts --platform=node --target=node20 --bundle --outfile=/tmp/test.cjs && node /tmp/test.cjs
Expected Result
/tmp/test.cjs generates /tmp/test.zip.
Actual Result
/tmp/test.cjs throws ReferenceError and fails.
ReferenceError: totalEntries is not defined
at Object.compressToBuffer (/tmp/test.cjs:1790:24)
at Object.writeZip (/tmp/test.cjs:2629:30)
at Object.<anonymous> (/tmp/test.cjs:2688:5)
Hints
Running node /path/to/the/following/script.js will succeed.
esbuild emits "use strict"; on top of the out file if it sees strict config in tsconfig.json. If you delete the first line of /tmp/test.cjs, the issue would disappear because in sloppy mode you just can assign to any global variable without a declaration.
I found cjs files generated from ts files sometimes throws ReferenceError. I found the problem with a project using
adm-zip
library.Reproduction
Using Node.js v20.15.0.
Steps
npm i && npx esbuild test.ts --platform=node --target=node20 --bundle --outfile=/tmp/test.cjs && node /tmp/test.cjs
Expected Result
/tmp/test.cjs generates /tmp/test.zip.
Actual Result
/tmp/test.cjs throws
ReferenceError
and fails.Hints
node /path/to/the/following/script.js
will succeed."strict": true
in the tsconfig.json, the reproduction will give the expected result.The text was updated successfully, but these errors were encountered: