gpt4 book ai didi

angular - 将AWS放大到Angular应用程序时出现错误: global is not defined

转载 作者:行者123 更新时间:2023-12-03 15:42:28 28 4
gpt4 key购买 nike

我正在测试从Angular到Cognito用户池的AWS Amplify,方法如下:

https://docs.amplify.aws/lib/restapi/getting-started/q/platform/js

Angular应用已成功编译,但是在Chrome控制台中抛出了异常:

index.js:43 Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (AuthenticationHelper.js:1)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/amazon-cognito-identity-js/es/index.js (index.js:1)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/@aws-amplify/auth/lib-esm/Auth.js (Auth.js:1)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/@aws-amplify/auth/lib-esm/index.js (index.js:1)
at __webpack_require__ (bootstrap:84)

请问一个主意吗?

最佳答案

this suggestion works in this case as well.

<script>
var global = global || window;
var Buffer = Buffer || [];
var process = process || {
env: { DEBUG: undefined },
version: []
};
</script>

或添加到 polyfills.ts的末尾
(window as any).global = window;
(window as any).process = {
env: { DEBUG: undefined },
};

关于angular - 将AWS放大到Angular应用程序时出现错误: global is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61555262/

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