gpt4 book ai didi

Angular + amazon-cognito-identity-js,为什么我收到错误 : global is not defined

转载 作者:行者123 更新时间:2023-12-01 22:10:29 26 4
gpt4 key购买 nike

从命令行:

ng new sandbox
cd .\sandbox\
ng serve

打开http://localhost:4200/ 。它有效。

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({});
}

刷新http://localhost:4200/ .

页面为空白。控制台出现错误:

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)

解决此错误的最佳方法是什么?

最佳答案

将其作为 /src/polyfills.ts 中的最后一行

(window as any).global = window

关于Angular + amazon-cognito-identity-js,为什么我收到错误 : global is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52175544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com