Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws-amplify js to angular app has error: global is not defined

I am testing AWS Amplify from Angular to Cognito User Pool following:

https://docs.amplify.aws/lib/restapi/getting-started/q/platform/js

The Angular app has successfully compiled however the exception throws out in the Chrome console:

index.js:43 Uncaught ReferenceError: global is not defined
at Object../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js (AuthenticationHelper.js:1)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/amazon-cognito-identity-js/es/index.js (index.js:1)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/@aws-amplify/auth/lib-esm/Auth.js (Auth.js:1)
at __webpack_require__ (bootstrap:84)
at Module../node_modules/@aws-amplify/auth/lib-esm/index.js (index.js:1)
at __webpack_require__ (bootstrap:84)

ANy idea please?

like image 598
beewest Avatar asked May 02 '20 06:05

beewest


People also ask

Does amplify support angular?

AWS Amplify enables Angular developers to create high-quality applications on a flexible, scalable, and reliable serverless backend.

How do I remove amplify authentication?

In order to unlink your existing Cognito resource run amplify remove auth . This will only unlink the Cognito resource referenced from the Amplify project. It will not delete the Cognito resource itself. Run amplify push to complete the unlink procedure.

Is amplify AWS good?

AWS Amplify supports faster development of apps and is also very helpful in on-going implementation. As Amazon Machine Learning services like Amazon SageMaker are supported, AWS Amplify is very useful for implementing machine learning and AI requirements.


2 Answers

this suggestion works in this case as well.

<script>
    var global = global || window;
    var Buffer = Buffer || [];
    var process = process || {
      env: { DEBUG: undefined },
      version: []
    };
  </script>

or add to the end of polyfills.ts

(window as any).global = window;
(window as any).process = {
  env: { DEBUG: undefined },
};
like image 126
beewest Avatar answered Sep 25 '22 06:09

beewest


The AWS docs suggest adding

(window as any).global = window;

(window as any).process = {
  env: { DEBUG: undefined },
};

to src/polyfills.ts

This has worked in my projects.

https://docs.amplify.aws/start/getting-started/data-model/q/integration/ionic#connect-frontend-to-api

like image 24
glenn Avatar answered Sep 23 '22 06:09

glenn