EventSource / eventsource

EventSource client for Node.js and Browser (polyfill)
MIT License
908 stars 252 forks source link

Use native EventSource in browsers #283

Closed Frando closed 2 years ago

Frando commented 2 years ago

Hi, this PR adds a browser field to package.json, with a browser.js that re-exports window.EventSource in CommonJS format. This makes the package easily compatible with CommonJS based bundlers (e.g. vite).

piranna commented 2 years ago

👎🏻 use standard exports field instead.

rexxars commented 2 years ago

I don't think this is a decision to be taken lightly.

Personally, I feel that this module is not a great fit for the browser even when using polyfills for http, https, url and similar, since it adds a significant amount of code and complexity. Having said that, this PR would be a big breaking change, and will only work in browsers with a native EventSource implementation. While that is thankfully the case for most modern browsers, it is not a drop-in replacement. For instance, the second argument to the constructor does not provide any way to specify headers in the browser, so it creates a mismatch in behavior between node and the browser which is annoying to deal with.