aws-sdk:从angular5更新为angular6后崩溃

时间:2018-05-10 01:50:03

标签: angular amazon-web-services typescript aws-sdk

我刚从Angular 5.2更新到Angular 6.0,我的代码现在突破了这个错误:

core.js:1601 ERROR Error: Uncaught (in promise): ReferenceError: global is 
not defined
ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browserHashUtils.js 
(browserHashUtils.js:1)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browserHmac.js (browserHmac.js:1)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browserCryptoLib.js 
(browserCryptoLib.js:1)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browser_loader.js (browser_loader.js:4)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browserHashUtils.js 
(browserHashUtils.js:1)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browserHmac.js (browserHmac.js:1)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browserCryptoLib.js 
(browserCryptoLib.js:1)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/aws-sdk/lib/browser_loader.js (browser_loader.js:4)
at __webpack_require__ (bootstrap:81)

有人知道这个问题吗? 我尝试过更新但似乎aws-sdk-js没有提供更新的原理图

4 个答案:

答案 0 :(得分:12)

将以下内容添加到polyfills.ts

{{1}}

答案 1 :(得分:4)

在此问题得到解决之前有一种解决方法,

尝试在index.html head标记中添加以下内容

<script>
  if (global === undefined) {
    var global = window;
  }
</script>

答案 2 :(得分:2)

  

ReferenceError:未定义global

修复

来自https://github.com/angular/angular-cli/issues/9920Node shims have been removed in 6.0

解决方案:破解的代码就是问题所在。至少那是角度的立场。例如。向aws-sdk等报告

答案 3 :(得分:1)

根据本文档(并由我测试):https://aws-amplify.github.io/amplify-js/media/angular_guide

您只需要将此行添加到顶部的polyfills.ts文件中:

x

这应该可以修复它,并且是正确的方法。