microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.25k stars 126 forks source link

ERROR in bundle from UglifyJs Unexpected token: punc (,) #205

Closed mhoofman closed 1 year ago

mhoofman commented 1 year ago

Our project's webpack build which uses UglifyJS (uglify-js) started erroring after the tslib update from 2.5.0 to 2.5.1.

Here is the error message we are seeing (I replaced the name of our bundle file w/ bundle.js):

ERROR in bundle.js from UglifyJs
Unexpected token: punc (,) [./~/tslib/tslib.es6.js:296,0][bundle.js:218700,13]

Here are the package versions used that create this build error:

We rolled back tslib to version 2.5.0 to fix our builds.

Can this older version of uglify-js be supported or should we work towards updating our package dependencies?

jakebailey commented 1 year ago

Seems like we wrote an object literal like { foo } but should have written { foo: foo }. @andrewbranch

Though, you must be using something truly ancient to not have that syntax... Webpack v2 I guess shows that just be the case. I'm surprised you don't see breaks somewhere else!

jakebailey commented 1 year ago

Per https://github.com/microsoft/tslib/pull/206#issuecomment-1557911549, this is exceptionally strange given export default was introduced in the same ECMAScript revision as the object literal shorthand, so a tool not doing both is very, very odd.

andrewbranch commented 1 year ago

should we work towards updating our package dependencies

Yes 😄

mhoofman commented 1 year ago

should we work towards updating our package dependencies

Yes 😄

Thanks for looking into this! I guess its time for us to move out of ancient history.

andrewbranch commented 1 year ago

Note that there should be other workarounds available to you, like

simeiyu commented 1 year ago

ERROR in static/js/index.js from UglifyJs Unexpected token: punc (,) [./node_modules/_tslib@2.5.2@tslib/tslib.es6.js:296,0][static/js/index.js:140813,13]

taurheim commented 1 year ago

I am running into this issue, but not related to UglifyJs, instead when trying to use webpack with typescript with an es5 target.

I have a minimum repro here: https://github.com/taurheim/webpack-typescript-es5-demo

@andrewbranch would appreciate your insights here, this might not be a tslib problem directly but it only broke with the new tslib version. Thanks!

andrewbranch commented 1 year ago

This all seems like everyone else’s bugs, not ours, but I guess we can just delete the offending syntax 🥴