下面是我的app.component和错误。我如何解决这个错误?
index.js:43 Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (vendor.js:69868)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/index.js (vendor.js:74053)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.component.ts (main.js:96)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.module.ts (app
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router,ActivatedRoute } from '@angular/router';
import { environment } from '../environments/environment';
//import * as AWSCognito from 'amazon-cognito-identity-js';
import {AuthenticationDetails, CognitoUser, CognitoUserAttribute, CognitoUserPool} from 'amazon-cognito-identity-js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit,OnDestroy {
title = 'app';
PoolData = {
UserPoolId: environment['pool_id'],
ClientId: environment['pool_app_client_id']
};
userPool:any;
constructor(public router: Router,
private route: ActivatedRoute){
this.userPool = new CognitoUserPool(this.PoolData);
}
ngOnInit(){
console.log(this.router.url)
this.route.queryParams.subscribe(params => {
console.log(params)
});
}
ngOnDestroy(){
}
}发布于 2018-08-30 10:05:11
这仅仅意味着没有定义节点使用的全局变量。Global in节点相当于javascript中的window。
有几种方法可以解决这个问题:
将以下内容添加到您的index.html标头:
<script>
if (global === undefined) {
var global = window;
}
</script>或添加到窗口:(window as any).global =polyfill.ts;
我想一个简单的谷歌搜索就能给你答案。
https://stackoverflow.com/questions/51219097
复制相似问题