pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

SyntaxError if used with Webpack and UglifyJs #64

Closed JanMalte closed 6 years ago

JanMalte commented 6 years ago

Version 4.0.0-rc3 throws an SyntaxError if used with Webpack and UglifyJs:

SyntaxError: Unexpected token: name (Event) [../~/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:3,0]

Version 3.2.2 can be used without any errors

pladaria commented 6 years ago

Can you please provide a minimal setup so I can reproduce it?

pladaria commented 6 years ago

Also note, latest library versions are published with ES6 code, you might need to review your setup if you need to transpile to ES5 or lower

andy12530 commented 6 years ago

[2018-06-06 15:47:17] error
[2018-06-06 15:47:17] [2018-06-06 15:47:17] /static/index.ff37ca.js from UglifyJs [2018-06-06 15:47:17] SyntaxError: Unexpected token: name (Event) [./~/reconnecting-websocket/dist/reconnecting-websocket-cjs.js:3,0] [2018-06-06 15:47:17] [2018-06-06 15:47:17] [2018-06-06 15:47:17] webpack: bundle build is now finished.

andy12530 commented 6 years ago

same error

wenq1 commented 6 years ago

ES6 to ES5 should be done by THIS module (via rollup), rather than by the final app. This changed somehow from 3.2.2 to 4.0-rc.

jobelenus commented 6 years ago

I'm having the same problem. I don't understand "THIS module (via rollup)" above? Essentially it seems that the events.ts file isn't properly processed by webpack babel-loader with es2015 presets. How should we work on packaging this with webpack?

Edit: its clear how this changed, the events.ts file

jobelenus commented 6 years ago

I'm even following: https://gist.github.com/nojaf/daf886031072b572bc9a and adding { test: /\.ts(x?)$/, loader: "babel-loader?presets[]=es2015!ts-loader" } to module loaders (and adding .ts to the extensions. And still getting errors running webpack for "Unexpected token". The error line is directly on the es6 export class ... line.

pladaria commented 6 years ago

Next release will target ES5. Thanks for reporting