Closed wdzeng closed 3 months ago
I believe this issue is due to adm-zip
itself: https://github.com/cthackers/adm-zip/issues/526
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.
Oh thanks!
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.