title: EventSource not working in angular 6 due to module http and https
body: <p>I am using an EventSource in my angular 6 project. When I try to run my project using <code>ng serve</code>, I get the following error:</p>
  
  <blockquote>
    <p>ERROR in ./node_modules/eventsource/lib/eventsource.js Module not
    found: Error: Can't resolve 'http' in
    '${MY_PATH}/node_modules/eventsource/lib'</p>
  </blockquote>
  
  <p>This error appears the same for '<strong>https</strong>' module. I tried to use the <code>HttpClientModule</code> instead of the <code>HttpModule</code> but it didn't work. I also tried to install the <code>EventSource</code> explicitly by running <code>npm install eventsource</code>, but the issue is still there.</p>
  
  <p>The code that I'm using:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  import * as EventSource from 'eventsource';
  
  @Injectable({
    providedIn: 'root'
  })
  export class MyService {
      private eventSource: EventSource;
  
      constructor(private http: HttpClient) {
          this.eventSource = new EventSource('/subscribe');
          this.eventSource.reconnectInterval = 1;
      }
  
      // Rest of the code omitted for clarity
  }
  </code></pre>