amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Error during "ng build" on Amplify Angular

Open etr opened this issue 1 year ago • 10 comments

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v20.15.1

Amplify CLI Version

12.12.4

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Describe the bug

I am using Amplify with Angular and Ionic. As I perform "ng build" I get the following error:

Error: node_modules/@aws-amplify/datastore/dist/esm/types.d.ts:256:363 - error TS2536: Type '"field"' cannot be used to index type 'MetadataOrDefault<T, M>["identifier"]'.

256 export type IdentifierFields<T extends PersistentModel, M extends PersistentModelMetaData<T> = never> = (MetadataOrDefault<T, M>['identifier'] extends ManagedIdentifier<any, any> | OptionallyManagedIdentifier<any, any> ? MetadataOrDefault<T, M>['identifier']['field'] : MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, infer B> ? B[number] : MetadataOrDefault<T, M>['identifier']['field']) & string;
                                                                                                                                                                                                                                                                                                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/datastore/dist/esm/types.d.ts:305:305 - error TS2536: Type 'MetadataOrDefault<T, M>["identifier"]["field"]' cannot be used to index type 'T'.

305 export type IdentifierFieldValue<T extends PersistentModel, M extends PersistentModelMetaData<T>> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any> ? MetadataOrDefault<T, M>['identifier']['fields'] extends [any] ? T[MetadataOrDefault<T, M>['identifier']['fields'][0]] : never : T[MetadataOrDefault<T, M>['identifier']['field']];
                                                                                                                                                                                                                                                                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/datastore/dist/esm/types.d.ts:305:307 - error TS2536: Type '"field"' cannot be used to index type 'MetadataOrDefault<T, M>["identifier"]'.

305 export type IdentifierFieldValue<T extends PersistentModel, M extends PersistentModelMetaData<T>> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any> ? MetadataOrDefault<T, M>['identifier']['fields'] extends [any] ? T[MetadataOrDefault<T, M>['identifier']['fields'][0]] : never : T[MetadataOrDefault<T, M>['identifier']['field']];
                                                                                                                                                                                                                                                                                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected behavior

No errors

Reproduction steps

  1. Start from an new amplify project
  2. Set up the package.json file as the attached one.
  3. npm i
  4. ng build

package.json

Project Identifier

9a1c6b8ab468bb739b4aaa401ebab656

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

etr avatar Jul 20 '24 23:07 etr

Hey👋 thanks for raising this! I'm going to transfer this over to our JS repository for better assistance 🙂

ykethan avatar Jul 25 '24 14:07 ykethan

Hello, @etr and sorry to hearing you're running into this. I'm wondering if this is tied to v18 of Angular and some TypeScript compatibility issues. Can you see if downgraded to v17 for Angular resolves this? In the mean time we'll look into why the build issues are happening with DataStore.

cwomack avatar Jul 26 '24 18:07 cwomack

Hey, thanks for the response. Unfortunately, even downgrading to v17 still produces the same issue.

Downgrading to Angular v16 did work though. I suspect that what made it work is that I could downgrade to typescript 4.9.4. Angular 17+ requires typescript 5+ which seems to be the culprit.

Attached a package.json that actually works.

package.json package-lock.json

etr avatar Jul 27 '24 23:07 etr

Hi, I'm experiencing something similar when upgrading from Angular v17 to v18 and trying to run the project, here is the error message, does amplify not support v18 yet?

Error: node_modules/@aws-amplify/datastore/lib-esm/types.d.ts:252:371 - error TS2536: Type '"field"' cannot be used to index type 'MetadataOrDefault<T, M>["identifier"]'.

252 export declare type IdentifierFields<T extends PersistentModel, M extends PersistentModelMetaData<T> = never> = (MetadataOrDefault<T, M>['identifier'] extends ManagedIdentifier<any, any> | OptionallyManagedIdentifier<any, any> ? MetadataOrDefault<T, M>['identifier']['field'] : MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, infer B> ? B[number] : MetadataOrDefault<T, M>['identifier']['field']) & string;


Error: node_modules/@aws-amplify/datastore/lib-esm/types.d.ts:301:313 - error TS2536: Type 'MetadataOrDefault<T, M>["identifier"]["field"]' cannot be used to index type 'T'.

301 export declare type IdentifierFieldValue<T extends PersistentModel, M extends PersistentModelMetaData<T>> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any> ? MetadataOrDefault<T, M>['identifier']['fields'] extends [any] ? T[MetadataOrDefault<T, M>['identifier']['fields'][0]] : never : T[MetadataOrDefault<T, M>['identifier']['field']];


Error: node_modules/@aws-amplify/datastore/lib-esm/types.d.ts:301:315 - error TS2536: Type '"field"' cannot be used to index type 'MetadataOrDefault<T, M>["identifier"]'.

301 export declare type IdentifierFieldValue<T extends PersistentModel, M extends PersistentModelMetaData<T>> = MetadataOrDefault<T, M>['identifier'] extends CompositeIdentifier<T, any> ? MetadataOrDefault<T, M>['identifier']['fields'] extends [any] ? T[MetadataOrDefault<T, M>['identifier']['fields'][0]] : never : T[MetadataOrDefault<T, M>['identifier']['field']];

× Failed to compile.

GustavWahl avatar Jul 30 '24 10:07 GustavWahl

I'm attempting to upgrade Angular to v17 and getting the same errors.

swiner-dlpx avatar Aug 27 '24 23:08 swiner-dlpx

i get the same upgrading to angular 18 - i don't want to upgrade to amplify gen2 as it would be far too much work for too little gain

craig-at-metashield-io avatar Sep 02 '24 09:09 craig-at-metashield-io

to get around this, i've "temporarily" added to tsconfig.ts

"compilerOptions": {
   ...
   "skipLibCheck": true
}

hopefully the angular team will get around to resolving this some time soon

craig-at-metashield-io avatar Sep 02 '24 09:09 craig-at-metashield-io

I ran into a similar problem. In my case, I was left with a place to import @aws-amplify, so I changed all these to aws-amplify and it worked. I hope this is helpful.

A-Kurimoto avatar Sep 07 '24 23:09 A-Kurimoto

We encountered the same issue during the upgrade to Angular 18

shox-harri avatar Oct 14 '24 09:10 shox-harri

I have the same problem with Angular 17...any update, solution or workaround? this is blocker.

Naikno avatar Oct 17 '24 11:10 Naikno

It's just that the types file of amplify-js does not support the strict mode of the latest typescript version needed by Angular. But it's just a check, your app will work fine.

As mentioned above, you can use "skipLibCheck": true as a workaround.

KeatsPeeks avatar Oct 29 '24 14:10 KeatsPeeks

Same error from my side. I'm upgrading Angular v16 to Angular v17 with @angular/cli@17 which updates the typescript version to 5.4.5. The error I'm getting is image

Adding "skipLibCheck": true solve the issue in my case.

VictorFrancoProminent avatar Nov 21 '24 19:11 VictorFrancoProminent

Encountered similar issue during the upgrade to Angular 18.

image

eXpertise7 avatar Dec 30 '24 15:12 eXpertise7