aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

Angular 15 error in node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts #10687

Closed JoakimMellonn closed 1 year ago

JoakimMellonn commented 1 year ago

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Storage

Amplify Categories

storage

Environment information

``` # Put output below this line System: OS: macOS 13.0 CPU: (10) arm64 Apple M1 Pro Memory: 973.45 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.11.0 - /opt/homebrew/bin/node npm: 9.1.2 - /opt/homebrew/bin/npm Browsers: Chrome: 107.0.5304.110 Safari: 16.1 npmPackages: @angular-devkit/build-angular: ^15.0.0 => 15.0.0 @angular/animations: ~15.0.0 => 15.0.0 @angular/cdk: ~15.0.0 => 15.0.0 @angular/cli: ~15.0.0 => 15.0.0 @angular/common: ~15.0.0 => 15.0.0 @angular/compiler: ~15.0.0 => 15.0.0 @angular/compiler-cli: ~15.0.0 => 15.0.0 @angular/core: ~15.0.0 => 15.0.0 @angular/forms: ~15.0.0 => 15.0.0 @angular/material: ~15.0.0 => 15.0.0 @angular/platform-browser: ~15.0.0 => 15.0.0 @angular/platform-browser-dynamic: ~15.0.0 => 15.0.0 @angular/router: ~15.0.0 => 15.0.0 @stripe/stripe-js: ^1.35.0 => 1.44.1 @types/file-saver: ^2.0.5 => 2.0.5 @types/jasmine: ~3.10.0 => 3.10.6 @types/node: ^12.11.1 => 12.20.55 (18.11.9) aws-amplify: ^5.0.2 => 5.0.2 docx: ^7.3.0 => 7.7.0 file-saver: ^2.0.5 => 2.0.5 ini: ^1.3.5 => 1.3.8 (3.0.1) inquirer: ^6.5.1 => 6.5.2 (8.2.4) jasmine-core: ~4.0.0 => 4.0.1 (3.99.1) karma: ~6.3.0 => 6.3.20 karma-chrome-launcher: ~3.1.0 => 3.1.1 karma-coverage: ~2.1.0 => 2.1.1 karma-coverage-coffee-example: 1.0.0 karma-jasmine: ~4.0.0 => 4.0.2 karma-jasmine-html-reporter: ~1.7.0 => 1.7.0 node-html-parser: ^5.3.3 => 5.4.2 rxjs: ~7.5.0 => 7.5.7 (6.6.7) rxjs/ajax: undefined () rxjs/fetch: undefined () rxjs/internal-compatibility: undefined () rxjs/operators: undefined () rxjs/testing: undefined () rxjs/webSocket: undefined () tslib: ^2.4.1 => 2.4.1 (1.14.1) typescript: ~4.8.4 => 4.8.4 webpack-cli: ^4.10.0 => 4.10.0 zone-mix: undefined () zone-node: undefined () zone-testing: undefined () zone.js: ~0.11.4 => 0.11.8 zone.js/async-stack-tagging: undefined () zone.js/async-stack-tagging.min: undefined () zone.js/async-test: undefined () zone.js/async-test.min: undefined () zone.js/fake-async-test: undefined () zone.js/fake-async-test.min: undefined () zone.js/jasmine-patch: undefined () zone.js/jasmine-patch.min: undefined () zone.js/long-stack-trace-zone: undefined () zone.js/long-stack-trace-zone.min: undefined () zone.js/mocha-patch: undefined () zone.js/mocha-patch.min: undefined () zone.js/proxy: undefined () zone.js/proxy.min: undefined () zone.js/sync-test: undefined () zone.js/sync-test.min: undefined () zone.js/task-tracking: undefined () zone.js/task-tracking.min: undefined () zone.js/webapis-media-query: undefined () zone.js/webapis-media-query.min: undefined () zone.js/webapis-notification: undefined () zone.js/webapis-notification.min: undefined () zone.js/webapis-rtc-peer-connection: undefined () zone.js/webapis-rtc-peer-connection.min: undefined () zone.js/webapis-shadydom: undefined () zone.js/webapis-shadydom.min: undefined () zone.js/wtf: undefined () zone.js/wtf.min: undefined () zone.js/zone-bluebird: undefined () zone.js/zone-bluebird.min: undefined () zone.js/zone-error: undefined () zone.js/zone-error.min: undefined () zone.js/zone-legacy: undefined () zone.js/zone-legacy.min: undefined () zone.js/zone-patch-canvas: undefined () zone.js/zone-patch-canvas.min: undefined () zone.js/zone-patch-cordova: undefined () zone.js/zone-patch-cordova.min: undefined () zone.js/zone-patch-electron: undefined () zone.js/zone-patch-electron.min: undefined () zone.js/zone-patch-fetch: undefined () zone.js/zone-patch-fetch.min: undefined () zone.js/zone-patch-jsonp: undefined () zone.js/zone-patch-jsonp.min: undefined () zone.js/zone-patch-message-port: undefined () zone.js/zone-patch-message-port.min: undefined () zone.js/zone-patch-promise-test: undefined () zone.js/zone-patch-promise-test.min: undefined () zone.js/zone-patch-resize-observer: undefined () zone.js/zone-patch-resize-observer.min: undefined () zone.js/zone-patch-rxjs: undefined () zone.js/zone-patch-rxjs-fake-async: undefined () zone.js/zone-patch-rxjs-fake-async.min: undefined () zone.js/zone-patch-rxjs.min: undefined () zone.js/zone-patch-socket-io: undefined () zone.js/zone-patch-socket-io.min: undefined () zone.js/zone-patch-user-media: undefined () zone.js/zone-patch-user-media.min: undefined () npmGlobalPackages: npm: 9.1.2 ```

Describe the bug

When running ´ng serve´ in my project after updating to Angular 15, I'm getting the following error message:

Error: node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:47:178 - error TS2344: Type 'T' does not satisfy the constraint 'Record<string, any>'.

47 export declare type StorageGetConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'get'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'get'>, T>;
                                                                                                                                                                                    ~

  node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:47:38
    47 export declare type StorageGetConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'get'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'get'>, T>;
                                            ~
    This type parameter might need an `extends Record<string, any>` constraint.

Error: node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:48:178 - error TS2344: Type 'T' does not satisfy the constraint 'Record<string, any>'.

48 export declare type StoragePutConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'put'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'put'>, T>;
                                                                                                                                                                                    ~

  node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:48:38
    48 export declare type StoragePutConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'put'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'put'>, T>;
                                            ~
    This type parameter might need an `extends Record<string, any>` constraint.

Error: node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:49:187 - error TS2344: Type 'T' does not satisfy the constraint 'Record<string, any>'.

49 export declare type StorageRemoveConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'remove'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'remove'>, T>;
                                                                                                                                                                                             ~

  node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:49:41
    49 export declare type StorageRemoveConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'remove'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'remove'>, T>;
                                               ~
    This type parameter might need an `extends Record<string, any>` constraint.

Error: node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:50:181 - error TS2344: Type 'T' does not satisfy the constraint 'Record<string, any>'.

50 export declare type StorageListConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'list'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'list'>, T>;
                                                                                                                                                                                       ~

  node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:50:39
    50 export declare type StorageListConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'list'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'list'>, T>;
                                             ~
    This type parameter might need an `extends Record<string, any>` constraint.

Error: node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:51:189 - error TS2344: Type 'T' does not satisfy the constraint 'Record<string, any>'.

51 export declare type StorageCopyConfig<T> = T extends StorageProviderWithCopy ? StorageOperationConfig<T, 'copy'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'copy'>, T>;
                                                                                                                                                                                               ~

  node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts:51:39
    51 export declare type StorageCopyConfig<T> = T extends StorageProviderWithCopy ? StorageOperationConfig<T, 'copy'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'copy'>, T>;
                                             ~
    This type parameter might need an `extends Record<string, any>` constraint.

When running the site locally, I can fix the problem by changing the lines 47-51 in node_modules/@aws-amplify/storage/lib-esm/types/Storage.d.ts from:

export declare type StorageGetConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'get'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'get'>, T>;
export declare type StoragePutConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'put'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'put'>, T>;
export declare type StorageRemoveConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'remove'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'remove'>, T>;
export declare type StorageListConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'list'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'list'>, T>;
export declare type StorageCopyConfig<T> = T extends StorageProviderWithCopy ? StorageOperationConfig<T, 'copy'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'copy'>, T>;

to:

export declare type StorageGetConfig<T extends Record<string, any>> = T extends StorageProvider ? StorageOperationConfig<T, 'get'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'get'>, T>;
export declare type StoragePutConfig<T extends Record<string, any>> = T extends StorageProvider ? StorageOperationConfig<T, 'put'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'put'>, T>;
export declare type StorageRemoveConfig<T extends Record<string, any>> = T extends StorageProvider ? StorageOperationConfig<T, 'remove'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'remove'>, T>;
export declare type StorageListConfig<T extends Record<string, any>> = T extends StorageProvider ? StorageOperationConfig<T, 'list'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'list'>, T>;
export declare type StorageCopyConfig<T extends Record<string, any>> = T extends StorageProviderWithCopy ? StorageOperationConfig<T, 'copy'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'copy'>, T>;

This isn't a problem when running it locally for development, but when I push it to Amplify Hosting, it just fails in the build step, with this same error.

My guess is that this happens because Angular 15 uses a newer version of TS, but tbh I don't really know much about this.

Expected behavior

Angular to launch without any error.

Reproduction steps

  1. Install aws-amplify package in an Angular 15 project.
  2. Import Storage from aws-amplify somewhere in project.
  3. Launch site with ng serve.
  4. Error.

Code Snippet

https://github.com/JoakimMellonn/Angular-Test-Project

Log output

``` // Put your logs below this line Site won't even launch. ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

BeyondAGI commented 1 year ago

Same issue for me. Any solutions?

JoakimMellonn commented 1 year ago

Same issue for me. Any solutions?

As written in the description, I found a solution for when doing it locally.

nadetastic commented 1 year ago

Hi @JoakimMellonn 👋,

Thank you for opening this issue, I was able to reproduce it and are working with the team to address it.

abdallahshaban557 commented 1 year ago

We have fixed this issue in our latest release! Please upgrade to V 5.0.4 and let us know if you are still facing this issue!