Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventSourcePolyfill is not defined #129

Open
ejerskov opened this issue Mar 24, 2019 · 5 comments
Open

EventSourcePolyfill is not defined #129

ejerskov opened this issue Mar 24, 2019 · 5 comments

Comments

@ejerskov
Copy link

Im working in ionic 4.10.2 with angular 7.3.5.

npm install event-source-polyfill

Then added this to the top of my file:

import 'event-source-polyfill/src/eventsource.js'
declare var EventSourcePolyfill: any;

And then using it like this:

    this.source = new EventSourcePolyfill(url, {
      headers: {
        "Authorization": "Bearer " + this.userService.user.token,
        "X-Requested-With": "XMLHttpRequest"
      }
    });

I then get the following error:

ERROR ReferenceError: EventSourcePolyfill is not defined

I've checked that the path is correct. Any other things Im missing?

@Yaffle
Copy link
Owner

Yaffle commented Mar 25, 2019

I am not using ionic, how show the typical export look like?

@ejerskov
Copy link
Author

I found the solution:
import { EventSourcePolyfill } from 'event-source-polyfill/src/eventsource.min.js'
The old way (in the Readme) seems not to work in newer angular projects

@Yaffle
Copy link
Owner

Yaffle commented Mar 26, 2019

@ejerskov , great, thanks

@Mweydert
Copy link

Mweydert commented Oct 14, 2019

The solution of @ejerskov didn't worked for me (Angular 8.0.1). The only way I found to make it works was to globally import the event-source-polyfill package.

import * as ssePolyfill from 'event-source-polyfill/src/eventsource.min.js';
new ssePolyfill.EventSourcePolyfill(url, opts);

However, I have no clue why this global import works while the named import didn't...

@Viktor-Bredihin
Copy link

@ejerskov
thanks, works great with angular 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants