Uncaught Error : t is not a constructor (aws-sdk)

0

I am hosting a Vite React app on Aws Amplify, for which I need cognito authentication and adding cognito users to groups.

So I installed { npm install aws-sdk } into my project and setup the CognitoIdentityServiceProvider from aws-sdk , created a user and added it to a specific group "locally".

But the moment I published the project to amplify, my app gave an error in the console as given below.

Uncaught TypeError: t is not a constructor at HOr (index.f006a380.js:2686:2491) at at (index.f006a380.js:2700:28195) at index.f006a380.js:2676:86676 at index.f006a380.js:1:146 at index.f006a380.js:2712:116468

and if i change the api version Enter image description here

I am using following versions of:

"@vitejs/plugin-react": "^2.2.0" "aws-sdk":"^2.1" "vite": "^3.2.6" "aws-amplify": "^5.0.12",

Vivek P
asked a year ago2975 views
2 Answers
0

It looks like the error you're getting is related to the AWS SDK for JavaScript. The error message "t is not a constructor" suggests that there might be an issue with the way the SDK is being imported or used in your code.

One possible solution to this error is to try updating the version of the AWS SDK for JavaScript that you're using in your project. It's possible that the version you're currently using is not compatible with the version of Vite React or other dependencies you have installed. You might want to try using a different version of the SDK and see if that resolves the issue.

Another possible solution is to check if the SDK is being imported correctly in your code. Make sure that you're importing the SDK as a constructor and not as a plain object. For example, instead of importing it like this:

import AWS from 'aws-sdk';

Try importing it like this:

import { CognitoIdentityServiceProvider } from 'aws-sdk';

If neither of these solutions work, it might be helpful to provide more information about your code and how you're using the AWS SDK for JavaScript, so that we can better understand the issue and provide more specific advice.

hash
answered a year ago
0

Ran into a similar error with a Vite Vue 3 application. I was able to fix the issue upgrading to v3 of the aws-sdk. This required a few minor changes to how I was authenticating users, I would recommend this page : https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cognito-identity-provider/index.html

Tanner
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions