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

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

Closed
4 tasks done
JulianHillworth opened this issue Oct 17, 2024 · 23 comments
Assignees
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. p1 This is a high priority issue potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@JulianHillworth
Copy link

JulianHillworth commented Oct 17, 2024

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

  • Select this option if this issue appears to be a regression.

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

@JulianHillworth JulianHillworth added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 17, 2024
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Oct 17, 2024
@JulianHillworth JulianHillworth changed the title TITLE FOR BUG REPORT AWS SDK 3 TypeError: 0, util_user_agent_browser_1.createDefaultUserAgentProvider is not a function Oct 17, 2024
@aBurmeseDev aBurmeseDev self-assigned this Oct 17, 2024
@aBurmeseDev
Copy link
Member

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.

@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Oct 17, 2024
@catarinadasilva
Copy link

catarinadasilva commented Oct 17, 2024

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
Copy link
Member

aBurmeseDev commented Oct 17, 2024

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
Copy link

catarinadasilva commented Oct 17, 2024

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
Copy link

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
Copy link
Member

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
Copy link

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
Copy link

catarinadasilva commented Oct 17, 2024

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
Copy link
Member

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

  • have you worked with other clients and is it same issue for all service clients or just CloudWatchLogsClient?
  • 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?

@catarinadasilva
Copy link

catarinadasilva commented Oct 17, 2024

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...

@aBurmeseDev aBurmeseDev added the investigating Issue is being investigated and/or work is in progress to resolve the issue. label Oct 18, 2024
@JulianHillworth
Copy link
Author

JulianHillworth commented Oct 18, 2024

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

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Oct 18, 2024
@aBurmeseDev
Copy link
Member

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
Copy link

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
Copy link

@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
Copy link

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

@aBurmeseDev aBurmeseDev added p1 This is a high priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet. and removed p2 This is a standard priority issue investigating Issue is being investigated and/or work is in progress to resolve the issue. labels Oct 18, 2024
@aBurmeseDev
Copy link
Member

aBurmeseDev commented Oct 18, 2024

Hi @catarinadasilva! Quick update; the fix was released in v3.675.0 and I've verified it on my end.

However, if anyone's still see the issue after upgrading to version 3.675.0, it is recommended that you remove the node_modules and/or the package-lock file, and then reinstall the required packages. This step can often resolve lingering issues related to dependencies and package versions.

Thanks again for reporting this!

@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. closing-soon This issue will automatically close in 4 days unless further comments are made. and removed pending-release This issue will be fixed by an approved PR that hasn't been released yet. labels Oct 18, 2024
@sqrter
Copy link

sqrter commented Oct 20, 2024

Not sure if this is related but I have the same issue while updating @aws-sdk/client-s3 and @aws-sdk/s3-request-presigner from 3.354.0 to 3.675.0. The last working version for me is 3.437.0

    err: {
      "type": "TypeError",
      "message": "(0 , util_user_agent_node_1.createDefaultUserAgentProvider) is not a function",
      "stack":
          TypeError: (0 , util_user_agent_node_1.createDefaultUserAgentProvider) is not a function
              at getRuntimeConfig (/node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js:39:71)
              at new S3Client (/node_modules/@aws-sdk/client-s3/dist-cjs/index.js:8421:65)
              at TestController.getImageUploadUrl (/src/controller.ts:121:16)
              at /node_modules/@nestjs/core/router/router-execution-context.js:38:29
              at processTicksAndRejections (node:internal/process/task_queues:105:5)
              at async /node_modules/@nestjs/core/router/router-execution-context.js:46:28
              at async /node_modules/@nestjs/core/router/router-proxy.js:9:17
    }

The executing code is like this:

    const s3 = new S3Client(this.appConfig.aws.client);
    const signedUrlExpireSeconds = 60 * 60;
    const command = new PutObjectCommand({
      Bucket: this.appConfig.aws.s3bucket,
      Key: `images/${newId()}`,
      ContentType: contentType
    });
    const url = await getSignedUrl(s3, command, {expiresIn: signedUrlExpireSeconds});
    return {url};

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. labels Oct 21, 2024
@catarinadasilva
Copy link

catarinadasilva commented Oct 21, 2024

Hello @aBurmeseDev, I can confirm that the version 3.675.0, does not have the original issue of this thread, however, the logs are not reaching cloudwatch, not sure where they are being sent but it seems that's not using the configurations parsed to the client, at least there are no changes on the code aside the npm install of the latest version.

PS: it works fine with version 3.669.0

UPDATE: @aBurmeseDev, the issue I've reported in this comment was due to another aspect of our setup and not related with the cloudwatch lib... everything works with the latest 3.675.0, thank for the fast fix

@kuhe kuhe added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 21, 2024
@aBurmeseDev
Copy link
Member

@catarinadasilva - appreciate the update and glad the issue is now resolved.

@sqrter - remove the node_modules directory and/or the package-lock file, and then reinstall the required packages. There might be lingering issues between dependencies and package versions.

@sqrter
Copy link

sqrter commented Oct 21, 2024

@aBurmeseDev Though reinstalling didn't help, I found where the problem was - in transitive dependencies. I had a resolution configuration for one of my dependencies, and one of its transitive dependencies was also used in @aws-sdk which led to the incorrect behavior. Thanks

@tomoima525
Copy link

Seems like this issue is still happening with node.js Lambda . Everything is freshly installed in my environment.

version: 3.679.0

image

{
  "errorType": "TypeError",
  "errorMessage": "(0 , util_user_agent_node_1.createDefaultUserAgentProvider) is not a function",
  "trace": [
    "TypeError: (0 , util_user_agent_node_1.createDefaultUserAgentProvider) is not a function",
    "    at getRuntimeConfig (/opt/nodejs/node_modules/email-layer/node_modules/@aws-sdk/client-sqs/dist-cjs/runtimeConfig.js:34:71)",
    "    at new SQSClient (/opt/nodejs/node_modules/email-layer/node_modules/@aws-sdk/client-sqs/dist-cjs/index.js:186:65)",
    "    at new SQS (/opt/nodejs/node_modules/email-layer/node_modules/@aws-sdk/client-sqs/dist-cjs/index.js:2261:12)",

@srdjanbogicevic
Copy link

I have the same problem, tried with new versions like 3.674.0, 3.675.0, 3.679.0 but it does not work.
Downgraded to 3.437.0 and it works now!

I am using:
"@aws-sdk/client-firehose": "3.437.0",
"@aws-sdk/client-s3": "3.437.0",
"@aws-sdk/s3-request-presigner": "3.437.0",

in NextJS project deployed as standalone service on ubuntu server. Node version is v18.17.0.

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. p1 This is a high priority issue potential-regression Marking this issue as a potential regression to be checked by team member
Projects
None yet
Development

No branches or pull requests

9 participants