aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.08k stars 575 forks source link

AWS SDK 3 TypeError: 0, util_user_agent_browser_1.createDefaultUserAgentProvider is not a function #6573

Open JulianHillworth opened 1 day ago

JulianHillworth commented 1 day ago

Checkboxes for prior research

Describe the bug

React Native Project

utilising @aws-sdk/client-cognito-identity-provider": "^3.654.0", @aws-sdk/client-dynamodb": "^3.654.0", @aws-sdk/client-s3": "^3.654.0", @aws-sdk/client-sns": "^3.654.0", @aws-sdk/client-sqs": "^3.654.0", @aws-sdk/credential-provider-cognito-identity": "^3.654.0", amazon-cognito-identity-js": "^6.3.12

Patched to

@aws-sdk/client-cognito-identity-provider 3.670.0
@aws-sdk/client-dynamodb 3.670.0 @aws-sdk/client-s3 3.673.0 @aws-sdk/client-sns 3.670.0
@aws-sdk/client-sqs 3.670.0 @aws-sdk/credential-provider-cognito-identity 3.670.0

npx expo run:android builds correctly. No issues on previous versions.

After applying updates and running npx expo run:android it also builds correctly once again.

When running the project receive error

TypeError: 0, util_user_agent_browser_1.createDefaultUserAgentProvider is not a function

This occurs on @aws-sdk/client-cognito-identity-provider and @aws-sdk/client-sns from what I can tell.

Uninstall modules reinstall previous versions. works correctly. Nothing else has changed in the project. Merely updating the AWS modules.

Regression Issue

SDK version number

AWS-SDK-JS-V3

Which JavaScript Runtime is this issue in?

React Native

Details of the browser/Node.js/ReactNative version

0.74.5

Reproduction Steps

To reproduce, run a build with the new patched dependencies compared to the previous.

Observed Behavior

AWS services @aws-sdk/client-cognito-identity-provider and @aws-sdk/client-sns will not work in the project.

Expected Behavior

To continue operation as per version updated from.

Possible Solution

What was changed, change back.

Additional Information/Context

Nil

aBurmeseDev commented 18 hours ago

Hi @JulianHillworth - thanks for reaching out.

Could you please confirm the issue with the latest release v3.674.0 and provide a minimal reproducible code snippet along with the error log? This will help us investigate and address the problem more effectively.

catarinadasilva commented 17 hours ago

I've had the same error, I've upgraded the react native version from 0.67.5 to 0.75.3 and the issue started appearing when trying to boot a Client using new CloudWatchLogsClient...

To reproduce, start a new react native app and create a dummy file that only calls the client, is enough to trigger the error on newer react native versions...

In my case, the error message is the following:

[TypeError: 0, _$$_REQUIRE(_dependencyMap[7](...)).createDefaultUserAgentProvider is not a function (it is undefined)]

aBurmeseDev commented 16 hours ago

Thanks for chiming in. Could you please verify with the latest SDK release, which is version 3.674.0? Additionally, I would appreciate if you could provide your SDK code snippet, as I haven't been able to replicate the problem you're encountering with the S3 ListObjectsCommand when testing it with React Native version 0.75.3.

catarinadasilva commented 16 hours ago

Hello @aBurmeseDev, the issue seems to be incompatibility with the react native above 0.74... I've done the following and was able to reproduce:

npx react-native@latest init Test --skip-install
yarn add @aws-sdk/client-cloudwatch-logs

Then I've added the following to App.tsx

import {
  CloudWatchLogsClient,
} from '@aws-sdk/client-cloudwatch-logs';
...
  useEffect(() => {
    new CloudWatchLogsClient({
      region: 'us-east-1',
    });
  }, []);

after that I've run yarn install and yarn ios And got this error

Screenshot 2024-10-17 at 11 02 58 PM
catarinadasilva commented 16 hours ago

The issue happens in both Android and iOS builds (the previous screenshot is iOS) In android shows this (is the same error)

Screenshot 2024-10-17 at 11 10 07 PM
aBurmeseDev commented 16 hours ago

Can you add the following polyfills and give it another try? npm install react-native-get-random-values react-native-url-polyfill web-streams-polyfill

import "react-native-get-random-values";
import "react-native-url-polyfill/auto";
import "web-streams-polyfill/dist/polyfill";

It's mentioned in our README that react-native environment requires certain polyfills to work with SDK:

If you are consuming modular AWS SDK for JavaScript on react-native environments, you will need to add and import following polyfills in your react-native application:

react-native-get-random-values react-native-url-polyfill web-streams-polyfill

catarinadasilva commented 16 hours ago

Same thing, even with those imports in the index.js the builder version can't access the createDefaultUserAgentProvider...

Screenshot 2024-10-17 at 11 16 31 PM Screenshot 2024-10-17 at 11 16 40 PM Screenshot 2024-10-17 at 11 16 46 PM Screenshot 2024-10-17 at 11 16 51 PM
catarinadasilva commented 15 hours ago

There is an important note: this issue seems to happen to all versions above 3.398.0 of the aws-sdk-js-v3.

The @aws-sdk/client-cloudwatch-logs was working with react native 0.67.5, but since the upgrade to the latest react-native version the issue started...

I've tried to rollback to react-native 0.67.5 and it started working again, however, we can't use that react-native version as Android requires a patch that's only available on versions above 0.72(that has the issue already)

aBurmeseDev commented 15 hours ago

Appreciate the additional details. A few more questions to verify before further investigation:

catarinadasilva commented 15 hours ago

have you worked with other clients and is it same issue for all service clients or just CloudWatchLogsClient?

We only using Cloudwatch logs, but I believe this happens in all clients when used by react native 0.7x

you stated that this issue started beyond version 3.398.0 of SDK which was released in Aug 2023. Can you verify that was the last working version?

I don't think the issue is directly related with the SDK version but an incompatibility with the newer versions of react-native, the 3.398.0 works on react-native 0.67.5 but not in 0.7x such as 0.75.3

My understanding is that the react native is not bundling properly the aws-sdk, almost as this package is being recognised as a dev package (even when defined in the dependencies)

Screenshot 2024-10-18 at 12 21 25 AM

PS: I've tried to add the @aws-sdk/util-user-agent-browser without success...

JulianHillworth commented 14 hours ago

Hi @JulianHillworth - thanks for reaching out.

Could you please confirm the issue with the latest release v3.674.0 and provide a minimal reproducible code snippet along with the error log? This will help us investigate and address the problem more effectively.

Hi, just tried it on cognito-identity-provider v3.670 again. v3.674 is still unavailable on NPM for cognito-identity-provider. Same issue. Revert it back to 3.654 works. Confirmed I have the polyfills installed. The other one i had issue with was SNS, that responded with the same error, latest version is still only v3.670

Code snippet

const handleGetUserCommand = async (accessToken: string) => {
  try {
    const command = new GetUserCommand({
      AccessToken: accessToken,
    });
    const response = await cognitoClient.send(command);
    return response;
  } catch (error) {
    console.log(`handleGetUserCommand error: `, error);
    return null;
  }
};

TypeError: 0, util_user_agent_browser_1.createDefaultUserAgentProvider is not a function (it is undefined), js engine: hermes

image

aBurmeseDev commented 12 hours ago

Thank you for providing comprehensive details; it assisted me in my testing process. After evaluating multiple versions, I have identified that v3.669.0 is the latest compatible version, while it appears that v3.670.0 introduced an incompatibility issue. While we further investigate, please remain on v3.669.0.

catarinadasilva commented 5 hours ago

Hello @aBurmeseDev, thanks for the help.

I've confirmed that version 3.669.0 does not trigger the error, we will remain on that version temporarily while you and your team fix the issue on a new version containing all the patches between 3.669.0 and 3.674.

aman-saraf commented 4 hours ago

@aBurmeseDev , this issue is happening on @aws-sdk/client-scheduler 3.674.0 as well. I tried downgrading the library to lower versions such as v3.670.0 , v3.665.0, but it's still not working. When I investigated the package-lock.json file, it was still downloading the v3.674.0 zip from npm even for the lower versions and even after deleting the package lock and node modules.

kevincarpdev commented 8 minutes ago

@catarinadasilva - thank you for your troubleshooting. I encountered the same error today. Downgrading to 3.669.0 worked for me as well.