ReferenceError: global is not defined with Stream and Angular 7.1

ReferenceError: global is not defined with Stream and Angular 7.1

我正在尝试将 Stream 与 Angular 7 一起使用,但出现以下错误。

ReferenceError: global is not defined ReferenceError: global is not defined at Object../node_modules/faye/src/util/browser/event.js (event.js:45) at webpack_require (bootstrap:83) at Object../node_modules/faye/src/protocol/client.js (client.js:8) at webpack_require (bootstrap:83) at Object../node_modules/faye/src/faye_browser.js (faye_browser.js:9) at webpack_require (bootstrap:83) at Object../node_modules/getstream/lib/lib/client.js (client.js:25) at webpack_require (bootstrap:83) at Object../node_modules/getstream/lib/getstream.js (getstream.js:6) at webpack_require (bootstrap:83) at resolvePromise (zone.js:814) at resolvePromise (zone.js:771) at zone.js:873 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:16147) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595)

我正在使用来自 npm 版本 4.1.0 的包 "getstream"。

这是一段代码以及我如何引用它。

import { Injectable } from '@angular/core';
import { Constants } from './../constants';
import * as stream from 'getstream';

@Injectable({
  providedIn: 'root'
})
export class ActivityService {
  userToken: string;
  streamClient: stream.Client;

  constructor(public azureService: AzureService) { 
    console.log("Activity Service");
  }

  async initializeClient() {
    try {
      await this.getUserToken();

      if (this.userToken) {
        this.streamClient = await stream.connect(Constants.streamKey, this.userToken, Constants.streamAppId);
      }
    }
    catch (error) {
      console.log('Error creating stream client - ', error);
      throw error;
    }
  }

我试过声明全局但我不确定还能尝试什么。在这种情况下导入和使用 Stream 的正确方法是什么?

这看起来像是一个 Angular 问题。他们确实为此提供了一些解决方法。 https://github.com/angular/angular-cli/issues/8160 https://github.com/angular/angular-cli/issues/9827#issuecomment-386154063

(window as any).global = window;