【问题标题】:angular v6 and amazon-cognito-identity-js角度 v6 和 amazon-cognito-identity-js
【发布时间】:2018-12-15 13:50:03
【问题描述】:

下面是我的 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(){

  }
}

【问题讨论】:

标签: angular aws-cognito


【解决方案1】:

这只是意味着节点使用的全局变量没有定义。节点中的全局相当于javascript中的窗口。

有几种方法可以解决这个问题:

将此添加到您的 index.html 标头中:

<script>
  if (global === undefined) {
    var global = window;
  }
</script>

或者添加到 polyfill.ts: (window as any).global = window;

我假设一个简单的谷歌搜索会给你答案。

【讨论】:

    猜你喜欢
    • 2019-05-19
    • 2019-12-11
    • 2020-12-09
    • 1970-01-01
    • 2019-01-24
    • 2021-09-13
    • 1970-01-01
    • 2022-01-02
    • 2022-01-24
    相关资源
    最近更新 更多