Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during "ng build" on Amplify Angular #13644

Open
2 tasks done
etr opened this issue Jul 20, 2024 · 13 comments
Open
2 tasks done

Error during "ng build" on Amplify Angular #13644

etr opened this issue Jul 20, 2024 · 13 comments
Labels
Angular Related to Angular 2+ Build Related to build issues DataStore Related to DataStore category pending-maintainer-response Issue is pending a response from the Amplify team. question General question transferred This issue was transferred from another Amplify project

Comments

@etr
Copy link

etr commented Jul 20, 2024

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:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@etr etr added the pending-triage Issue is pending triage label Jul 20, 2024
@ykethan
Copy link
Member

ykethan commented Jul 25, 2024

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

@ykethan ykethan transferred this issue from aws-amplify/amplify-cli Jul 25, 2024
@ykethan ykethan added the transferred This issue was transferred from another Amplify project label Jul 25, 2024
@cwomack cwomack added the Angular Related to Angular 2+ label Jul 26, 2024
@cwomack
Copy link
Member

cwomack commented Jul 26, 2024

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 cwomack added question General question Build Related to build issues DataStore Related to DataStore category pending-response and removed pending-triage Issue is pending triage labels Jul 26, 2024
@etr
Copy link
Author

etr commented Jul 27, 2024

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

@GustavWahl
Copy link

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.

@swiner-dlpx
Copy link

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

@craig-at-metashield-io
Copy link

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
Copy link

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

@A-Kurimoto
Copy link

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.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Sep 7, 2024
@shox-harri
Copy link

We encountered the same issue during the upgrade to Angular 18

@Naikno
Copy link

Naikno commented Oct 17, 2024

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

@KeatsPeeks
Copy link

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.

@VictorFrancoProminent
Copy link

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.

@eXpertise7
Copy link

eXpertise7 commented Dec 30, 2024

Encountered similar issue during the upgrade to Angular 18.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Angular Related to Angular 2+ Build Related to build issues DataStore Related to DataStore category pending-maintainer-response Issue is pending a response from the Amplify team. question General question transferred This issue was transferred from another Amplify project
Projects
None yet
Development

No branches or pull requests