【问题标题】:MongoDB Stitch in Angular 7 applicationAngular 7 应用程序中的 MongoDB Stitch
【发布时间】:2019-09-04 03:38:21
【问题描述】:

我正在尝试在我的 Angular 7 应用程序中添加与 MongoDB Stich 的连接,但应用程序失败并出现错误:

bson.browser.esm.js:453 Uncaught ReferenceError: global is not defined

我正在使用 Angular 7.2.12 并已安装 mongodb-stitch-browser-sdk v 4.3.2

我正在使用 MongoDB 网站上 DB Stitch 应用程序客户端设置下的代码。

import { Component, OnInit } from '@angular/core';
import { Stitch, RemoteMongoClient, AnonymousCredential} from 'mongodb-stitch-browser-sdk'

@Component({
  selector: 'app-alfabetisk',
  templateUrl: './alfabetisk.component.html',
  styleUrls: ['./alfabetisk.component.css']
})
export class AlfabetiskComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    const client = Stitch.initializeDefaultAppClient('app-id');
  }
}

应用程序在 ngOnInit() 中失败并出现错误:

bson.browser.esm.js:453 Uncaught ReferenceError: global is not defined 在 Module../node_modules/bson/dist/bson.browser.esm.js (bson.browser.esm.js:453) 在 webpack_require (bootstrap:78) 在 Module../node_modules/mongodb-stitch-core-sdk/dist/esm/index.js (index.js:1) 在 webpack_require (bootstrap:78) 在 Module../node_modules/mongodb-stitch-browser-core/dist/esm/index.js (index.js:1) 在 webpack_require (bootstrap:78) 在 Module../node_modules/mongodb-stitch-browser-sdk/dist/esm/index.js (index.js:1) 在 webpack_require (bootstrap:78) 在 Module../src/app/alfabetisk/alfabetisk.component.ts (main.js:95) 在 webpack_require (bootstrap:78)

【问题讨论】:

    标签: angular mongodb mongodb-stitch


    【解决方案1】:

    将此添加到 Angular 6+ 的 polyfills.ts

    /** Add global to window */
    (window as any).global = window;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2019-08-31
      • 1970-01-01
      • 2016-08-25
      • 2020-08-29
      相关资源
      最近更新 更多