From a command line:
ng new sandbox
cd .\sandbox\
ng serve
Open http://localhost:4200/. It works.
npm install --save amazon-cognito-identity-js
Inside \src\app\sign-up\sign-up.component.ts
add this line of code:
import * as AmazonCognitoIdentity from 'amazon-cognito-identity-js';
Add a constructor:
constructor() {
new AmazonCognitoIdentity.CognitoUserPool({});
}
Refresh http://localhost:4200/.
Page is blank. There is a console error:
Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (AuthenticationHelper.js:1)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/amazon-cognito-identity-js/es/index.js (index.js:1)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.component.ts (main.js:94)
at __webpack_require__ (bootstrap:76)
at Object../src/app/app.module.ts (app.component.ts:9)
at __webpack_require__ (bootstrap:76)
What is the best way to resolve this error?
Put this as the last line in /src/polyfills.ts
(window as any).global = window
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With