gpt4 book ai didi

Angular 6 未捕获的 ReferenceError : Buffer is not defined

转载 作者:太空狗 更新时间:2023-10-29 17:00:23 32 4
gpt4 key购买 nike

我尝试使用 ng update 从 5 迁移到 6,但出现错误

Uncaught ReferenceError: Buffer is not defined
at Object../node_modules/amazon-cognito-identity-js/node_modules/crypto-browserify/helpers.js (helpers.js:2)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/amazon-cognito-identity-js/node_modules/crypto-browserify/md5.js (md5.js:10)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/amazon-cognito-identity-js/node_modules/crypto-browserify/create-hash.js (create-hash.js:3)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/amazon-cognito-identity-js/node_modules/crypto-browserify/index.js (index.js:12)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (vendor.js:47207)
at __webpack_require__ (bootstrap:81)

本地环境非常适合创建新的 Angular 项目。我不使用缓冲区。这是幕后的事情

有什么想法吗?

UPD

我正在尝试更新@types/node npm install --save-dev @types/node

+ @types/node@8.9.5
updated 1 package in 12.031s
[!] 26 vulnerabilities found [36141 packages audited]
Severity: 11 Low | 13 Moderate | 2 High
Run `npm audit` for more detail

如果我运行 npm audit

npm ERR! code ENOAUDIT
npm ERR! audit Your configured registry (https://registry.npmjs.org/) does not support audit requests.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/myname/.npm/_logs/2018-05-16T13_45_17_410Z-debug.log

最佳答案

好的,一个小时后,我终于设法让 Cognito 在我的 Angular 应用程序上运行(刚刚升级到 6.0)。

关于消息 global is not defined (或者一些不记得的关闭)。将以下内容添加到 index.html 中:

<!doctype html>
<html lang="en">
<head>
...

<script>
var global = global || window;
</script>
</head>

然后,您可能会收到一条错误消息,指出 Buffer 未定义。

使用 npm 或 yarn 安装 buffer 包。并将以下内容添加到 polyfills.ts () 中:

global.Buffer = global.Buffer || require('buffer').Buffer;

Stackoverflow answers/github issues 对我有帮助,以防它在那之后没有为你修复:

Upgrading to angular-6.x gives "Uncaught ReferenceError: global is not defined"

https://github.com/aws/aws-amplify/issues/840#issuecomment-389459988

https://github.com/aws/aws-amplify/issues/678

https://github.com/aws/aws-amplify/issues/153

https://github.com/crypto-browserify/createHash/issues/20

关于Angular 6 未捕获的 ReferenceError : Buffer is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50371593/

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