aws-amplifyaws-amplify-sdk-js

Problem in configure method of AWS Amplify JavaScript library after upgrade to 5.3.7


I just upgraded my NodeJS project which upgraded my aws-amplify library and encountered with multiple breaking changes. I was able to fix all except the two. Following is my updated package.json file:-

{
  "name": "project",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.4.2",
    "@fortawesome/free-brands-svg-icons": "^6.4.2",
    "@fortawesome/free-solid-svg-icons": "^6.4.2",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "@types/nprogress": "^0.2.0",
    "aws-amplify": "^5.3.7",
    "axios": "^1.4.0",
    "colors": "^1.4.0",
    "next": "13.4.16",
    "nprogress": "^0.2.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-dropzone": "^14.2.3",
    "react-select": "^5.7.4",
    "sass": "^1.65.1"
  },
  "devDependencies": {
    "@types/node": "^20.5.0",
    "@types/react": "18.2.20",
    "eslint": "8.47.0",
    "eslint-config-next": "13.4.16",
    "typescript": "5.1.6"
  }
}

1st error is on this following line which says property configure does not exist on type typeof....:-

Amplify.configure(AmplifyConfig);

I'm importing the AWS Cognito configuration from a function defined in a separate TypeScript file like import { AmplifyConfig } from "../configs";

export const AmplifyConfig = {
  Auth: {
    // REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
    identityPoolId: "<>",

    // REQUIRED - Amazon Cognito Region
    region: "<>",

    // OPTIONAL - Amazon Cognito Federated Identity Pool Region
    // Required only if it's different from Amazon Cognito Region
    identityPoolRegion: "<>",

    // OPTIONAL - Amazon Cognito User Pool ID
    userPoolId: "<>",

    // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
    userPoolWebClientId: "<>",

    oauth: {
      domain: "XXXXXXXXX.com",
      scope: [
        "phone",
        "email",
        "openid",
        "profile",
        "aws.cognito.signin.user.admin",
      ],
      redirectSignIn: process.env.PROD_CALLBACK_URL,
      redirectSignOut: process.env.PROD_SIGNOUT_URL,
      responseType: "token", // or 'token', note that REFRESH token will only be generated when the responseType is code
    },
  },
  ssr: true,
};

Solution

  • Please ignore, I'm able to solve it by importing as a function:-

    import { Amplify, Auth } from "aws-amplify";
    

    and then Amplify.configure(AmplifyConfig);