Angular integration problem with aws-amplify when signing up with Google account

I am attempting to integrate AWS-Amplify(^4.3.0) with angular-12 and typescript (4.3.5). I have followed the documentation to configure amplify properly, but when trying to start the app, I encountered some amplify errors as shown below.

Warning: D:\Google Sign-IN Demo\google-test\node_modules\amazon-cognito-identity-js\es\AuthenticationHelper.js depends on 'crypto-js/lib-typedarrays'. CommonJS or AMD dependencies can cause optimization bailouts. For more information, please refer to: https://angular.io/guide/build#configuring-commonjs-dependencies

Warning: D:\Google Sign-IN Demo\google-test\node_modules\amazon-cognito-identity-js\es\Client.js depends on 'isomorphic-unfetch'. CommonJS or AMD dependencies can cause optimization bailouts. For more information, please refer to: https://angular.io/guide/build#configuring-commonjs-dependencies

Error: node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:44:46 - error TS2344: Type 'T[U]' does not satisfy the constraint '(...args: any) => any'. Type 'T["get"] | T["copy"] | T["put"] | T["remove"] | T["list"]' is not assignable to type '(...args: any) => any'. Type 'T["copy"]' is not assignable to type '(...args: any) => any'. Type '((src: StorageCopyTarget, dest: StorageCopyDestination, config?: any) => Promise) | ((src: StorageCopyTarget, dest: StorageCopyDestination, config?: any) => Promise<...>) | undefined' is not assignable to type '(...args: any) => any'. Type 'undefined' is not assignable to type '(...args: any) => any'.

44 } : U extends 'copy' ? never : LastParameter<T[U]> & { ~~~~

Type 'T["get"] | T["copy"] | T["put"] | T["remove"] | T["list"]' is not assignable to type '(...args: any) => any'. Type 'T["copy"]' is not assignable to type '(...args: any) => any'. Type '((src: StorageCopyTarget, dest: StorageCopyDestination, config?: any) => Promise) | undefined' is not assignable to type '(...args: any) => any'. Type 'undefined' is not assignable to type '(...args: any) => any'.

58 declare type PickProviderOutput<DefaultOutput, T, api extends StorageProviderApi> = T extends StorageProvider ? T['getProviderName'] extends 'AWSS3' ? Promise : ReturnType<T[api]> : T extends {

Following the documentation, after fully configuring AWS-Amplify with Cognito, I added the following code in main.ts:

import Amplify from "aws-amplify";
import aws_exports from "./aws-exports";
Amplify.configure(aws_exports);

Any assistance would be greatly appreciated! Please advise me on where I might be going wrong?

Answer №1

After carrying out my own tests, I experienced the same issue. This specific problem is observed in Angular 12 due to the default activation of strict mode (as mentioned in the documentation), which clashes with the @aws-amplify/storage type. In order to work around this error, you can disable it by adjusting these settings:

{
  "compilerOptions": {
    ...
    "strictNullChecks": false,
  }
}

However, it may be beneficial to raise an issue on their repository to ensure that their storage type aligns with strict mode, especially if you are inclined to do so.

edit: Further investigation revealed additional compiler options for resolving the error.

Answer №2

If you want to prevent optimization bailouts caused by CommonJS or AMD dependencies, simply insert the following code snippet into the build section of your angular.json file:

"allowedCommonJsDependencies": [
      "crypto-js",
      "isomorphic-unfetch"

   ]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in Angular SSR: Build failed due to project reference without "composite" setting set to true

Currently facing an issue while developing an Angular App with SSR. When using npm run build:ssr, the following errors are displayed: ERROR in [...]/tsconfig.json [tsl] ERROR TS6306: Referenced project '[...]/tsconfig.app.json' must have se ...

Watching the Event Emitters emitted in Child Components?

How should we approach utilizing or observing parent @Output() event emitters in child components? For instance, in this demo, the child component utilizes the @Output onGreetingChange as shown below: <app-greeting [greeting]="onGreetingChange | a ...

Unusual Conduct when Interacting with ContentEditable Text

Looking for help with a strange issue that I can't seem to figure out. Hopefully someone has encountered this before and might have a solution. In my Angular app, I'm using a contenteditable <div> for inputting content, which is working fi ...

How to Pass a JSON Object to a Child Component in Angular and Display It Without Showing "[Object

Need help with my API call implementation. Here's a snippet from my Input component: Input.html <form (submit)="getTransactions()"> <div class="form-group"> <label for="exampleInputEmail1"></label> <input type="t ...

Encountering an issue with MUI Props: "Must provide 4 to 5 type arguments."

I'm attempting to use a custom component and pass in AutocompleteProps as a prop, all while utilizing typescript. Here's my current setup: type Props = { autoCompleteProps?: AutocompleteProps<T> label: string loading?: boolean } cons ...

The routing system in Angular 4 seems to have trouble functioning properly when accessed from within the Laravel public folder

Currently, I am facing a challenge with deploying my Laravel JSON API which is being used by an Angular 4 application. During deployment, I utilize Forge and place the contents of the "dist" folder within Laravel's public directory. However, I am enco ...

An issue arises in Slate.js when attempting to insert a new node within a specified region, triggering an error

A relevant code snippet: <Slate editor={editor} value={value} onChange={value => { setValue(value); const { selection } = editor; // if nothing is currently selected under the cursor if (select ...

Assigning enum type variable using string in TypeScript

How can I dynamically assign a value to a TypeScript enum variable? Given: enum options { 'one' = 'one', 'two' = 'two', 'three' = 'three'} let selected = options.one I want to set the variable " ...

Issue with Nuxt: Property accessed during rendering without being defined on the instance

As I attempt to create cards for my blog posts, I encountered an issue with a Post component in my code. The cards are displaying like shown in the picture, but without any text. How do I insert text into these cards? Currently, all the text is within attr ...

Angular is not rendering styles correctly

Having two DOMs as depicted in the figures, I'm facing an issue where the circled <div class=panel-heading largeText"> in the first template receives a style of [_ngcontent-c1], while that same <div> gets the style of panel-primary > .pane ...

What is the process for importing a TypeScript module from the local directory?

I am currently working on a TypeScript module with plans to eventually release it on NPM. However, before publishing, I want to import the module into another project hosted locally for testing purposes. Both projects are written in TypeScript. The TypeSc ...

Is there a way to integrate a calendar feature within an Angular 2 application?

I am brand new to Angular 2 and have a question: I need to integrate a calendar into a page where users can add events. Something similar to the following example: I'm unsure if the angular material calendar project is designed for Angular 2 or for ...

The "fullName" input remains constant despite any changes made during text input

Currently, I am in the process of implementing a ControlValueAccessor in a child form. In my setup, there is a parent form group and control structured like this: this.form = this.formBuilder.group({ user: ['', Validators.required] ...

What is the best way to fetch all Firebase database IDs using Angular?

Is there a way to fetch all data from Firebase database along with their respective IDs? Currently, I have two functions - getAll() and get(input) that retrieve specific products based on the given ID. However, my current implementation only returns obje ...

Declare the push method within the Countly.q array in a TypeScript declaration file

Is there a way to declare Countly push add_event method in the following manner? Countly.q.push(['add_event',{ "key":"action_open_web", }]); I attempted to do this inside a declaration file (.d.ts) but it did not work. Here ...

Custom type checker that validates whether all properties of a generic object are not null or undefined

In an attempt to create a user-defined type guard function for a specific use-case, I am faced with a challenge: There are over 100 TypeScript functions, each requiring an options object. These functions utilize only certain properties from the object wh ...

Issue with Angular 4: Radio button defaults not being set

After hardcoding the value in component.ts, I am able to see the pre-selected radio button. However, when attempting to retrieve the value from sessionStorage, it does not work as expected. The value is visible in the console though. Could someone please ...

The process of HTML compilation is halted due to the unexpected presence of the forbidden 'null' data type, despite the fact that null cannot actually be a valid value in

Encountering an issue with my HTML code, where the compiler stops at: Type 'CustomItem[] | null | undefined' is not compatible with type 'CustomItem[] | undefined'. Type 'null' cannot be assigned to type 'CustomItem[] ...

Encountering issues with Angular 12 optimized build, the error messages are sparse and offer little

While my project compiles without any issues in development mode with the build optimizer turned off, I encounter an error during production build: ✔ Browser application bundle generation complete. ✔ ES5 bundle generation complete. ✔ Copying assets c ...

Solve the issue of the __typename union

Imagine having the following union: export type IBookmarkItemFragment = | ({ __typename: "Story" } & { story: number; }) | ({ __typename: "Product" } & { product: number; }) | ({ __typename: "Project" } & { proj ...