Error during "ng build" on Amplify Angular
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
- Start from an new amplify project
- Set up the package.json file as the attached one.
- npm i
- ng build
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.
Hey👋 thanks for raising this! I'm going to transfer this over to our JS repository for better assistance 🙂
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.
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.
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.
I'm attempting to upgrade Angular to v17 and getting the same errors.
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
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
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.
We encountered the same issue during the upgrade to Angular 18
I have the same problem with Angular 17...any update, solution or workaround? this is blocker.
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.
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
Adding "skipLibCheck": true solve the issue in my case.
Encountered similar issue during the upgrade to Angular 18.