我试图在我的Angular 7应用程序中添加与MongoDB Stich的连接但是app失败并出现错误:
bson.browser.esm.js:453未捕获的ReferenceError:未定义全局
我使用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未捕获的ReferenceError:在webpack_require的Module ../ node_modules / bson / dist / bson.browser.esm.js(bson.browser.esm.js:453)中未定义global.bootstrap: 78)在Module ../ node_modules / mongodb-stitch-core-sdk / dist / esm / index.js(index.js:1)at webpack_require(bootstrap:78)at Module ../ node_modules / mongodb-stitch-browser在webpack_require(bootstrap:78)的-core / dist / esm / index.js(index.js:1)在Module ../ node_modules / mongodb-stitch-browser-sdk / dist / esm / index.js(index.js) :1)at webpack_require(bootstrap:78)at module ../ src / app / alfabetisk / alfabetisk.component.ts(main.js:95)at webpack_require(bootstrap:78)
将其添加到polyfills.ts for Angular 6+
/** Add global to window */
(window as any).global = window;