Angular 6 Uncaught ReferenceError:未定义缓冲区

Angular 6 Uncaught ReferenceError:未定义缓冲区

问题描述:

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

I am trying to migrate from 5 to 6 using ng update and I get an error

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)

本地环境非常适合创建新的角度项目.我不使用缓冲区.这是幕后的东西

Local environment works well for creating the new angular project. I don't use Buffer. It is something behind the scenes

有什么想法吗?

UPD

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

I was trying to update @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

好了,一个小时后,我终于设法对Angular应用程序进行了cognito的工作(仅在升级到6.0之后).

Ok, after an hour I finally managed to have cognito working on my Angular app (just after upgrading to 6.0).

关于消息global is not defined(或者附近的东西不记得了).将以下内容添加到 index.html :

About the message global is not defined (or something close can't remember). Add the following into index.html:

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

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

然后,您可能会收到一条错误消息,提示未定义Buffer.

Then, you'll probably get an error saying that Buffer is not defined.

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

Install the buffer package using npm or yarn. And add the following into polyfills.ts ():

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

Stackoverflow答案/github问题,在此之后为您解决的情况下,对我有帮助:

Stackoverflow answers/github issues that helped me in case it's not fixed for you after that:

升级到有角-6.x给出未捕获的ReferenceError:未定义全局"

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