3

Yesterday i have migrated my application from Angular 5 to angular 7. In that process i have changed EventSource to EventSourcePolyfill as suggested while running the application. But since then i am facing a strange issue. This is what i am getting the issue in console as follows:

ERROR TypeError: Cannot read property 'heartbeatTimeout' of undefined
    at new EventSourcePolyfill (eventsource.js:155)
    at AppFooterComponent.push../src/app/layout/footer/footer.component.ts.AppFooterComponent.connect (footer.component.ts:133)
    at SafeSubscriber._next (footer.component.ts:52)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:196)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:134)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
    at AsyncAction.dispatch (timer.js:31)
    at AsyncAction.push../node_modules/rxjs/_esm5/internal/scheduler/AsyncAction.js.AsyncAction._execute (AsyncAction.js:63)
    at AsyncAction.push../node_modules/rxjs/_esm5/internal/scheduler/AsyncAction.js.AsyncAction.execute (AsyncAction.js:51)

This is what i did in my code:

import { EventSourcePolyfill } from 'ng-event-source';

let source = new EventSourcePolyfill('/api/v1/events/register');

Can any one suggest me how to get rid of this issue.

Thanks.

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
youi
  • 1,887
  • 5
  • 20
  • 31
  • The origin of the error is in footer.component.ts(line 133), kindly check it there. heartbeatTimeout might not be in the properties of the object you are trying to read. – inthevortex Nov 15 '18 at 05:30
  • When i comment it out then it works properly. I mean the EventSourcePolyfill is commented the it works fine. Its not the issue with the footer.component.ts. The code in footer.component.ts of EventSourcePoyfill breaks. Please suggest. – youi Nov 15 '18 at 05:38
  • Have you used `ng update` command for migration? It has ability to refactor some breaking changes? Have you followed instructions on [update.angular.io](https://update.angular.io/)? There are some steps with RxJS migration. – Walter Luszczyk Nov 22 '18 at 06:59

1 Answers1

1

You have to pass additional parameters, as

eventSource = new EventSourcePolyfill(url,
    { heartbeatTimeout: 5000, connectionTimeout: 5000, headers: { 'Authorization': 'Basic foo' }});
jay
  • 477
  • 5
  • 13