AOT runtime error with AWS Amplify and Angular 7 - API is not defined

240 Views Asked by At

I have set up AWS Amplify in an Angular 7 project using the API module for GraphQL capabilities.

All seems to work when served using ng serve.

If however if I use AOT compilation - e.g. For a production build then I receive no compilation errors but on runtime I see the following error

ERROR Error: Uncaught (in promise): ReferenceError: API is not defined

I have isolated the problem in that AOT is the trigger for it occurring but unsure whether it is an Amplify issue or something silly I am doing regarding Angular.

What am I doing wrong and how can I resolve it?

1

There are 1 best solutions below

0
On

For anyone else with this issue try prefixing API with Amplify.API. Not sure why it worked with JIT but not AOT but it solved the problem for me.