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

Application is not compiling due to the typing #13050

Closed
3 tasks done
julien-bitaillou opened this issue Feb 26, 2024 · 20 comments
Closed
3 tasks done

Application is not compiling due to the typing #13050

julien-bitaillou opened this issue Feb 26, 2024 · 20 comments
Assignees
Labels
Core Related to core Amplify issues question General question

Comments

@julien-bitaillou
Copy link

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

None

Environment information

# Put output below this line
angular: 17
typescript:5.3.3
@aws-amplify/ui-angular: 5.0.10
aws-amplify: 6.0.17

Describe the bug

Application is not compiling due to the typing

Expected behavior

Application to compile

Reproduction steps

after migration from v5 to v6

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line

Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:10 - error TS2339: Property 'type' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
             ~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:16 - error TS2339: Property 'error' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
                   ~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:23 - error TS2339: Property 'url' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
                          ~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signOut.ts:67:11 - error TS2339: Property 'type' does not exist on type 'void | OpenAuthSessionResult | {}'.

67   const { type } =
             ~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/updateMFAPreference.ts:48:4 - error TS7030: Not all code paths return a value.

48 ): CognitoMFASettings | undefined {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/credentialsProvider/credentialsProvider.ts:62:4 - error TS7030: Not all code paths return a value.

62    return;
      ~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/credentialsProvider/credentialsProvider.ts:67:4 - error TS7030: Not all code paths return a value.

67    return;
      ~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/oauth/completeOAuthFlow.ts:144:3 - error TS2322: Type 'JsonPrimitive | JsonObject | JsonArray' is not assignable to type 'string'.
  Type 'number' is not assignable to type 'string'.

144   username,
      ~~~~~~~~

  node_modules/@aws-amplify/auth/src/providers/cognito/tokenProvider/cacheTokens.ts:12:3
    12   username: string;
         ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'AuthenticationResultType & { NewDeviceMetadata?: DeviceMetadata; username: string; signInDetails?: CognitoAuthSignInDetails; }'


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/oauth/completeOAuthFlow.ts:207:3 - error TS2322: Type 'JsonPrimitive | JsonObject | JsonArray' is not assignable to type 'string'.

207   username,
      ~~~~~~~~

  node_modules/@aws-amplify/auth/src/providers/cognito/tokenProvider/cacheTokens.ts:12:3
    12   username: string;
         ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'AuthenticationResultType & { NewDeviceMetadata?: DeviceMetadata; username: string; signInDetails?: CognitoAuthSignInDetails; }'


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/signInHelpers.ts:854:4 - error TS7030: Not all code paths return a value.

854 ): AuthSignInOutput | undefined {
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/signInHelpers.ts:978:44 - error TS7030: Not all code paths return a value.

978 export function getMFAType(type?: string): AuthMFAType | undefined {
                                               ~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/core/src/clients/middleware/retry/defaultRetryDecider.ts:19:34 - error TS2339: Property 'code' does not exist on type '(Error & MetadataBearer) | (Error & { code: string; })'.
  Property 'code' does not exist on type 'Error & MetadataBearer'.

19   const errorCode = parsedError?.code;
                                    ~~~~


Error: node_modules/@aws-amplify/core/src/clients/serde/json.ts:17:3 - error TS7030: Not all code paths return a value.

17   return;


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

@julien-bitaillou julien-bitaillou added the pending-triage Issue is pending triage label Feb 26, 2024
@cwomack
Copy link
Member

cwomack commented Feb 26, 2024

Hello, @julien-bitaillou and thanks for opening this issue. Since you've recently upgraded from v5 to v6, can you see if taking the following steps helps resolve the type errors you're experiencing?

  • Delete your node_modules folder
  • Delete your package-lock.json file
  • Reinstall dependences with npm install

If the type errors persist after taking the above steps, then let me know and we'll dig deeper!

@cwomack cwomack added question General question Core Related to core Amplify issues pending-response and removed pending-triage Issue is pending triage labels Feb 26, 2024
@cwomack cwomack self-assigned this Feb 26, 2024
@julien-bitaillou
Copy link
Author

Hello @cwomack, the type error persist after deleting the node_module folder and the lock file

@chrisbonifacio
Copy link
Member

Hello @cwomack, the type error persist after deleting the node_module folder and the lock file

In order for us to be able to help, can you please share some more details about the type errors you're seeing?

If you have the error messages, logs, reproduction steps, code snippets, etc please share them as well.

@julien-bitaillou
Copy link
Author

We have the following logs:


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:10 - error TS2339: Property 'type' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
             ~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:16 - error TS2339: Property 'error' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
                   ~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signInWithRedirect.ts:113:23 - error TS2339: Property 'url' does not exist on type 'void | OpenAuthSessionResult | {}'.

113  const { type, error, url } =
                          ~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/signOut.ts:67:11 - error TS2339: Property 'type' does not exist on type 'void | OpenAuthSessionResult | {}'.

67   const { type } =
             ~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/apis/updateMFAPreference.ts:48:4 - error TS7030: Not all code paths return a value.

48 ): CognitoMFASettings | undefined {
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/credentialsProvider/credentialsProvider.ts:62:4 - error TS7030: Not all code paths return a value.

62    return;
      ~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/credentialsProvider/credentialsProvider.ts:67:4 - error TS7030: Not all code paths return a value.

67    return;
      ~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/oauth/completeOAuthFlow.ts:144:3 - error TS2322: Type 'JsonPrimitive | JsonObject | JsonArray' is not assignable to type 'string'.
  Type 'number' is not assignable to type 'string'.

144   username,
      ~~~~~~~~

  node_modules/@aws-amplify/auth/src/providers/cognito/tokenProvider/cacheTokens.ts:12:3
    12   username: string;
         ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'AuthenticationResultType & { NewDeviceMetadata?: DeviceMetadata; username: string; signInDetails?: CognitoAuthSignInDetails; }'


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/oauth/completeOAuthFlow.ts:207:3 - error TS2322: Type 'JsonPrimitive | JsonObject | JsonArray' is not assignable to type 'string'.

207   username,
      ~~~~~~~~

  node_modules/@aws-amplify/auth/src/providers/cognito/tokenProvider/cacheTokens.ts:12:3
    12   username: string;
         ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'AuthenticationResultType & { NewDeviceMetadata?: DeviceMetadata; username: string; signInDetails?: CognitoAuthSignInDetails; }'


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/signInHelpers.ts:854:4 - error TS7030: Not all code paths return a value.

854 ): AuthSignInOutput | undefined {
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/auth/src/providers/cognito/utils/signInHelpers.ts:978:44 - error TS7030: Not all code paths return a value.

978 export function getMFAType(type?: string): AuthMFAType | undefined {
                                               ~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@aws-amplify/core/src/clients/middleware/retry/defaultRetryDecider.ts:19:34 - error TS2339: Property 'code' does not exist on type '(Error & MetadataBearer) | (Error & { code: string; })'.
  Property 'code' does not exist on type 'Error & MetadataBearer'.

19   const errorCode = parsedError?.code;
                                    ~~~~


Error: node_modules/@aws-amplify/core/src/clients/serde/json.ts:17:3 - error TS7030: Not all code paths return a value.

17   return;

@rcoundon
Copy link

rcoundon commented Mar 1, 2024

It appears that you're not excluding node_modules from the TypeScript compiler. In tsconfig.json try setting

"compilerOptions": {
...
"exclude": [
    "./node_modules/**/*",
  ],
}
...

@julien-bitaillou
Copy link
Author

We still have errors with the exclude option

@rcoundon
Copy link

rcoundon commented Mar 5, 2024

Can you share your code? We're using v6 with TypeScript and we're not seeing this. It definitely looks to me from the logs you shared that the compiler is trying to compile library code.
When you exclude node_modules in tsconfig.json, are they the same errors?

@julien-bitaillou
Copy link
Author

The errors are the same, according to typescript documentation, import statement include the file to the code base even if it is in the exclude option.

@rcoundon
Copy link

rcoundon commented Mar 5, 2024

Do you have anything set for include? How are you importing the libraries in your code? Can you share a reproduction?

@nadetastic
Copy link
Member

Hi @julien-bitaillou adding to what @rcoundon asked above, it would also be helpful if you can share your tsconfig.json file as well to try and reproduce this issue.

@cwomack
Copy link
Member

cwomack commented Mar 29, 2024

@julien-bitaillou if you're still experiencing this issue, can you provide you tsconfig.json or sample code that's causing these errors? We need a little more context to understand what's happening and potentially reproduce the issue on our side. Thanks!

@atinary-ndefago
Copy link

Hello everyone, thanks for looking into this,
I am also experiencing the issue, here's the different relevant files that may help to debug it, let me know if something is missing:

tsconfig.base.json
{
    "compileOnSave": false,
    "angularCompilerOptions": {
        "strictTemplates": true
    },
    "compilerOptions": {
        "rootDir": ".",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "resolveJsonModule": true,
        "importHelpers": true,
        "target": "ES2020",
        "module": "esnext",
        "lib": ["ES2021", "ES2019", "ES2018", "ES2017", "ES2016", "ES2015", "dom"],
        "types": ["node", "jest"],
        "skipLibCheck": true,
        "skipDefaultLibCheck": true,
        "esModuleInterop": true,
        "paths": {
            "@angular/*": ["../../node_modules/@angular/*"],
            ...
        }
    },
    "watchOptions": {
        "excludeDirectories": ["**/node_modules"]
    },
    "exclude": ["./node_modules/**/*", "tmp/**/*", "setEnv.ts"]
}
app tsconfig.json
{
    "extends": "../../tsconfig.base.json",
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./out-tsc/app",
        "types": [],
        "target": "ES2022",
        "useDefineForClassFields": false
    },
    "files": ["src/main.ts", "src/polyfills.ts"],
    "include": ["src/**/*.d.ts"]
}
package.json
{
    "name": "front-end",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {
        "ng": "nx",
        "postinstall": "npm run environments && node ./decorate-angular-cli.js",
        "start": "nx serve",
        "build": "nx build",
        "test": "nx test",
        "environments": "ts-node tools/setEnv.ts",
        "prettier": "npx prettier apps/**/src --write",
        "e2e": "ng e2e"
    },
    "private": true,
    "devDependencies": {
        "@angular/core": "17.2.4",
        "@nrwl/angular": "18.1.2",
        "@types/node": "^18.16.9",
        "rxjs": "7.4.0",
        "typescript": "5.3.3",
        ...
    },
    "dependencies": {
        "aws-amplify": "6.0.26",
        ...
    },
    "engines": {
        "node": ">=18",
        "npm": ">=10"
    }
}

and here is how I import and use the function in my code:

import { signInWithRedirect } from 'aws-amplify/auth';

...

await signInWithRedirect({ provider: { custom: environment.SSO_IDP_NAME } });

I have recently upgraded from v5 to v6, tried to delete node_modules and the lock file but the issue persists

@ralphkurche
Copy link

I also get a build error starting with release v6.0.17:

Error: node_modules/@aws-amplify/core/src/clients/middleware/retry/defaultRetryDecider.ts:19:34 - error TS2339: Property 'code' does not exist on type '(Error & MetadataBearer) | (Error & { code: string; })'.
  Property 'code' does not exist on type 'Error & MetadataBearer'.

19   const errorCode = parsedError?.code;

I work with a legacy project which doesn't use the TS strict settings.
If I set "strictNullChecks": true in my tsconfig.json the error in the defaultRetryDecider.ts seems to disappear, but unfortunately I cannot build my project in its current state with this setting.

@ralphkurche
Copy link

Okay, my bad. I had a deeper look and found that I was accidentally importing a type from the src folder.
By replacing import { HubCallback } from '@aws-amplify/core/src'; with import { HubCallback } from '@aws-amplify/core/dist/esm';the src package is no longer included in the build.
I just realized this, after running tsc with the "explainFiles": true flag.

@cwomack
Copy link
Member

cwomack commented Apr 4, 2024

@ralphkurche, glad to hear you're unblocked!

@atinary-ndefago, thanks for providing dependencies. Are you getting the same errors reported by OP or a different type error?

@atinary-ndefago
Copy link

It was the same error, adding "strictNullChecks": true to my tsconfig solved it, thanks @ralphkurche!

@atinary-ndefago
Copy link

Okay, my bad, I was also importing stuff from from '@aws-amplify/core/src'; after changing to from '@aws-amplify/core/dist/esm'; it works well indeed

@cwomack
Copy link
Member

cwomack commented Apr 9, 2024

@julien-bitaillou, are you still experiencing this?

@mohammedsahl
Copy link

Okay, my bad, I was also importing stuff from from '@aws-amplify/core/src'; after changing to from '@aws-amplify/core/dist/esm'; it works well indeed

Can confirm this fixes all of the import errors. I was facing errors similar to #13050 (comment). Thanks atinary-ndefago

@cwomack
Copy link
Member

cwomack commented Apr 30, 2024

@mohammedsahl, thank you for the confirmation! Closing this issue for now after getting a few comments stating this can be resolved.

@cwomack cwomack closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to core Amplify issues question General question
Projects
None yet
Development

No branches or pull requests

8 participants