Yaffle / EventSource

a polyfill for http://www.w3.org/TR/eventsource/
MIT License
2.11k stars 336 forks source link

Upgrading to v1.x.x fails to load on Edge/IE11 #121

Closed EPinci closed 6 years ago

EPinci commented 6 years ago

Hello! I have a VUE/Webpack project that uses this EventSource polyfill on Edge/IE11. Version 0.0.16 works fine. If I upgrade to v1.0.3, the EventSource object doesn't get created (verified from browser console) and, subsequently, HMR fails as well. Am I missing something in the version change? Thank you.

Yaffle commented 6 years ago

I know nothing about VUE/Webpack/HMR, please provide a code changed needed to fix the problem

EPinci commented 6 years ago

Hey, first of all, thank you for getting back to me!

I'm actually new to those technologies as well and I'm still ramping up on debugging it. I know that this is the result of just changing the version tag in the package.json (no changes in scripts or bundling process). I cannot see any error on the console but the HMR complaining about the missing EventSource support after the version change and that got me to try to query for the object existence. I'm comparing the two javascript from v0.0.16 and v1.0.3 and I can't find anything that catches my eye if not for the closing block that I cannot reason out. Any chance you changed the way the polyfill has to be initialized?

Thank you!

Yaffle commented 6 years ago

there is another similar issue - https://github.com/Yaffle/EventSource/issues/117

EPinci commented 6 years ago

Uhm, that look like it is trying to do something custom, I'm just running the polyfill.

Ok, lacking (myself) a better "finesse" for this I diff'ed the 0.0.16 and the 1.0.3 and then reapplied the changes one by one: looks like the "braking part" is the one at the very end (lines 884+). When you change from:

 global.EventSourcePolyfill = EventSourcePolyfill;
  global.NativeEventSource = NativeEventSource;

to

(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
      var v = factory(exports);
      if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
      define(["exports"], factory);
    }
    else {
      factory(global);
    }
  })(function (exports) {
    exports.EventSourcePolyfill = EventSourcePolyfill;
    exports.NativeEventSource = NativeEventSource;

then the polyfill fails to load. It looks pretty obscure to me. do you know what that change does?

Thank you.