Angular + Amazon-Cognito-identity-js,我为什么会出错:全局未定义 [英] Angular + amazon-cognito-identity-js, why am I getting error: global is not defined
本文介绍了Angular + Amazon-Cognito-identity-js,我为什么会出错:全局未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从命令行:
ng new sandbox
cd .\sandbox\
ng serve
npm install --save amazon-cognito-identity-js
内部 \src\app\sign-up\sign-up.component.ts
添加以下代码行:
import * as AmazonCognitoIdentity from 'amazon-cognito-identity-js';
添加构造函数:
constructor() {
new AmazonCognitoIdentity.CognitoUserPool({});
}
页面为空白。出现控制台错误:
Page is blank. There is a console error:
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 (AuthenticationHelper.js:1)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/index.js (index.js:1)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.component.ts (main.js:94)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.module.ts (app.component.ts:9)
at __webpack_require__ (bootstrap:76)
解决此错误的最佳方法是什么?
What is the best way to resolve this error?
推荐答案
将此作为最后一行 /src/polyfills.ts
(window as any).global = window
这篇关于Angular + Amazon-Cognito-identity-js,我为什么会出错:全局未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文