Angular 7 で global is not defined

Angular 7 で AWS Amplify を使って Cognito と S3 を使ったアプリを開発中に、以下のエラーに遭遇しましたので、対処方法をメモしておきます。

index.js:43 Uncaught ReferenceError: global is not defined
    at Object../node_modules/buffer/index.js (index.js:43)
    at __webpack_require__ (bootstrap:78)
    at Object../node_modules/aws-sdk/lib/browserHashUtils.js (browserHashUtils.js:1)
    at __webpack_require__ (bootstrap:78)
    at Object../node_modules/aws-sdk/lib/browserHmac.js (browserHmac.js:1)
    at __webpack_require__ (bootstrap:78)
    at Object../node_modules/aws-sdk/lib/browserCryptoLib.js (browserCryptoLib.js:1)
    at __webpack_require__ (bootstrap:78)
    at Object../node_modules/aws-sdk/lib/browser_loader.js (browser_loader.js:4)
    at __webpack_require__ (bootstrap:78)

1. src/polyfills.ts に以下を記述

src/polyfills.ts の末尾に以下を記述します。

(window as any).global = window;

以上。

コメントする