aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.05k stars 574 forks source link

Error: URL.hostname is not implemented in React Native AWS Textract integration #6191

Closed ketan-pcs closed 2 months ago

ketan-pcs commented 3 months ago

Checkboxes for prior research

Describe the bug

I'm encountering an error while integrating AWS Textract with a React Native application. When attempting to analyze an ID document using the AnalyzeIDCommand from the @aws-sdk/client-textract package, I'm receiving the following error message: [Error: URL.hostname is not implemented]

SDK version number

3.592.0

Which JavaScript Runtime is this issue in?

React Native

Details of the browser/Node.js/ReactNative version

0.74.1

Reproduction Steps

[Error: URL.hostname is not implemented]

Observed Behavior

 const textRactFunction = async () => {
    if (imageData?.data) {
      const client = new TextractClient({
        region: 'us-east-1',
        credentials: {
          accessKeyId: 'YOUR_ACCESS_KEY_ID',
          secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',
        },
      });

      const blob = Buffer.from(imageData?.data, 'base64');

      const params = {
        DocumentPages: [
          {
            Bytes: blob,
          },
        ],
      };

      const command = new AnalyzeIDCommand(params);

      try {
        const textRactData = await client.send(command);

        // process data.

         console.log(textRactData.IdentityDocuments[0].IdentityDocumentFields);
      } catch (error) {
        console.log('TextractClient err', error);
        // error handling.
      }
    }
  };

Expected Behavior

give a response

Possible Solution

No response

Additional Information/Context

No response

RanVaknin commented 3 months ago

Hi @ketan-pcs ,

Did you add any polyfills?

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

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

Thanks, Ran~

github-actions[bot] commented 3 months ago

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] commented 2 months ago

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.