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

Unable to resolve module @aws-sdk/chunked-blob-reader when using S3Client #4631

Closed
3 tasks done
coofzilla opened this issue Apr 12, 2023 · 14 comments
Closed
3 tasks done
Assignees
Labels
bug This issue is a bug. p1 This is a high priority issue

Comments

@coofzilla
Copy link

coofzilla commented Apr 12, 2023

Checkboxes for prior research

Describe the bug

Xcode 14.2
Build version 14C18

ProductName: macOS
ProductVersion: 13.2.1
BuildVersion: 22D68

I am trying to use the S3Client from the @aws-sdk/client-s3 package in my React Native project, but I am encountering an error related to a missing dependency: @aws-sdk/chunked-blob-reader. Can someone help me resolve this issue or let me know what I'm missing?

Error: Unable to resolve module @aws-sdk/chunked-blob-reader 

package.json:

{
  "name": "AmazonExample",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.71.6",
    "@aws-sdk/client-cognito-identity": "^3.18.0",
    "@aws-sdk/client-s3": "^3.18.0",
    "@aws-sdk/credential-provider-cognito-identity": "^3.18.0",
    "react-native-get-random-values": "^1.6.0",
    "react-native-url-polyfill": "^1.3.0",
    "uuid": "^3.4.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.9",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

Additionally, I checked that I do have the required dependency.

➜  AmazonExample yarn list --pattern @aws-sdk/chunked-blob-reader
yarn list v1.22.19
└─ @aws-sdk/[email protected]
✨  Done in 0.22s.
yarn list v1.22.19
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
├─ @aws-sdk/[email protected]
└─ @aws-sdk/[email protected]

SDK version number

"@aws-sdk/client-s3": "^3.18.0",

Which JavaScript Runtime is this issue in?

React Native

Details of the browser/Node.js/ReactNative version

node -v v16.19.0, "react-native": "0.71.6"

Reproduction Steps

Steps to reproduce:

  1. Create a new React Native project.

  2. Install the required AWS SDK packages.

        "@aws-sdk/client-cognito-identity": "^3.18.0",
        "@aws-sdk/client-s3": "^3.18.0",
        "@aws-sdk/credential-provider-cognito-identity": "^3.18.0",
  3. Follow the example code provided in the AWS SDK for JavaScript documentation.
    https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/reactnative/App.js

  4. Run the project and error pops up.

Observed Behavior

When trying to use the S3Client in a React Native project, the application encounters the following error:

Error: Unable to resolve module @aws-sdk/chunked-blob-reader from /path/to/project/node_modules/@aws-sdk/hash-blob-browser/dist-cjs/index.js: @aws-sdk/chunked-blob-reader could not be found within the project or in these directories:
  node_modules
  2 | Object.defineProperty(exports, "__esModule", { value: true });
  3 | exports.blobHasher = void 0;
> 4 | const chunked_blob_reader_1 = require("@aws-sdk/chunked-blob-reader");
    |                                        ^
  5 | const blobHasher = async function blobHasher(hashCtor, blob) {
  6 |     const hash = new hashCtor();
  7 |     await (0, chunked_blob_reader_1.blobReader)(blob, (chunk) => {
    at ModuleResolver.resolveDependency (/path/to/project/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:162:15)
    at DependencyGraph.resolveDependency (/path/to/project/node_modules/metro/src/node-haste/DependencyGraph.js:260:43)
    at Object.resolve (/path/to/project/node_modules/metro/src/lib/transformHelpers.js:177:21)
    at Graph._resolveDependencies (/path/to/project/node_modules/metro/src/DeltaBundler/Graph.js:432:35)
    at Graph._processModule (/path/to/project/node_modules/metro/src/DeltaBundler/Graph.js:218:38)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Graph._addDependency (/path/to/project/node_modules/metro/src/DeltaBundler/Graph.js:314:20)
    at async Promise.all (index 16)
    at async Graph._processModule (/path/to/project/node_modules/metro/src/DeltaBundler/Graph.js:263:5)
    at async Graph._addDependency (/path/to/project/node_modules/metro/src/DeltaBundler/Graph.js:314:20)

The error occurs even when following the example repository provided in the AWS documentation:

https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/reactnative/App.js

Expected Behavior

I expected the S3Client to be imported and successfully initialized without any Errors. After following the example provided in the AWS documentation, I expected to be able to use the S3Client to upload a blob of video data to an S3 bucket.

Possible Solution

No response

Additional Information/Context

Here is the snippet for my actual use case; however, I was able to observe the error even in a brand new project with no configuration.

const useUploadVideo = () => {
  const { mutate, data, isLoading, isError, isSuccess, reset } = useMutation({
    mutationFn: async ({
      videoUri,
      userKey,
      identityPoolId = "some_ID",
      region = "some_REGION",
      s3Bucket = `some-bucket-name`,
    }: UploadVideoParams) => {
      // Fetch the video file and create a blob
      const response = await fetch(videoUri)
      const blob = await response.blob()

      // Create the S3 key for the video
      const key = `s3.amazonaws.com/somePath/${userKey}/testUpload/`

      // Initialize the S3Client
      // https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started-react-native.html
      const s3Client = new S3Client({
        region,
        credentials: fromCognitoIdentityPool({
          client: new CognitoIdentityClient({ region }),
          identityPoolId: `${region}:${identityPoolId}`,
        }),
      })

      // Create the PutObjectCommand with the required parameters
      // https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html
      const command = new PutObjectCommand({
        Bucket: s3Bucket,
        Key: key,
        Body: blob,
        ContentType: blob.type,
      })

      try {
        // Upload the video to S3
        const s3Result = await s3Client.send(command)
        console.log(s3Result)
        return s3Result
      } catch (err) {
        return console.error(err)
      }
    },
  })

  return { mutate, data, isLoading, isError, isSuccess, reset }
}
@coofzilla coofzilla added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2023
@cpyle0819
Copy link

Seeing this in latest: @aws-sdk/client-s3": "^3.310.0"

@cpyle0819
Copy link

Looks like for RN it's trying to resolve to @aws-sdk/chunked-blob-reader-native, but that module isn't present.
Screenshot 2023-04-12 at 12 32 56 PM
Screenshot 2023-04-12 at 12 34 14 PM

@cpyle0819
Copy link

When I build a package that has a browser entry in package.json, it creates a *.browser module in the outputs.
Screenshot 2023-04-12 at 2 44 53 PM
But when I build a package that has the react-native entry, it doesn't output anything different:
Screenshot 2023-04-12 at 2 45 04 PM

@cpyle0819
Copy link

Looks like this was the PR that removed the dep. #4571

@yenfryherrerafeliz yenfryherrerafeliz added investigating Issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2023
@coofzilla
Copy link
Author

Looks like this was the PR that removed the dep. #4571

I ended up installing these version for now, essentially prior to the removal. And it appears to be working.

"@aws-sdk/client-cognito-identity": "3.298.0",
"@aws-sdk/client-s3": "3.298.0",
"@aws-sdk/credential-provider-cognito-identity": "3.298.0",

@Hudson-AmalembaL
Copy link

Hello @coofzilla did you manage a solution, bug is still there.

@rveramx
Copy link

rveramx commented May 18, 2023

Hello @coofzilla did you manage a solution, bug is still there.

Install @aws-sdk/chunked-blob-reader-native

@RanVaknin RanVaknin self-assigned this May 22, 2023
@RanVaknin RanVaknin added the p2 This is a standard priority issue label May 22, 2023
@dpyeates
Copy link

dpyeates commented Jul 4, 2023

Any update on this? Still not able to go any higher than 3.298.0.
Installing @aws-sdk/chunked-blob-reader-native gives me other errors.

@RanVaknin
Copy link
Contributor

Hey @cpyle0819,

Thanks for the investigation. I will assign a higher priority for this and try to get this fixed asap.
Ran~

@RanVaknin RanVaknin added needs-review This issue/pr needs review from an internal developer. p1 This is a high priority issue and removed investigating Issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue labels Jul 5, 2023
@RanVaknin
Copy link
Contributor

Hi @dpyeates @rveramx @Hudson-AmalembaL @coofzilla , @cpyle0819 ,

We just pushed a fix that reintroduces the missing dependency.
Can you please test if this solves your issue?

Thanks 👍 ,
Ran~

@RanVaknin RanVaknin added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-review This issue/pr needs review from an internal developer. labels Jul 6, 2023
@kuhe
Copy link
Contributor

kuhe commented Jul 6, 2023

The fix is in https://github.com/awslabs/smithy-typescript/releases/tag/%40smithy%2Fhash-blob-browser%401.0.2

When updating, ensure that this package version is being used in any lockfiles you may have. For example, a fresh install of https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.367.0 should bring in the above package.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jul 7, 2023
@dpyeates
Copy link

dpyeates commented Jul 14, 2023

Still not working for me.

Using

"@aws-sdk/client-s3": "^3.370.0",
"@aws-sdk/s3-request-presigner": "^3.370.0",

I am getting the following error:

/node_modules/@smithy/util-stream/dist-cjs/getAwsChunkedEncodingStream.js: stream could not be found

@cpyle0819
Copy link

cpyle0819 commented Jul 25, 2023

@RanVaknin I'm getting the same error as @dpyeates. Happens when running locally.

error: Error: Unable to resolve module stream from /Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/node_modules/@smithy/util-stream/dist-cjs/getAwsChunkedEncodingStream.js: stream could not be found within the project or in these directories:
  ../../../node_modules
  2 | Object.defineProperty(exports, "__esModule", { value: true });
  3 | exports.getAwsChunkedEncodingStream = void 0;
> 4 | const stream_1 = require("stream");
    |                           ^
  5 | const getAwsChunkedEncodingStream = (readableStream, options) => {
  6 |     const { base64Encoder, bodyLengthChecker, checksumAlgorithmFn, checksumLocationName, streamHasher } = options;
  7 |     const checksumRequired = base64Encoder !== undefined &&
    at ModuleResolver.resolveDependency (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:162:15)
    at DependencyGraph.resolveDependency (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/node-haste/DependencyGraph.js:260:43)
    at Object.resolve (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/lib/transformHelpers.js:177:21)
    at Graph._resolveDependencies (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/DeltaBundler/Graph.js:432:35)
    at Graph._processModule (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/DeltaBundler/Graph.js:218:38)
    at async Graph._addDependency (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/DeltaBundler/Graph.js:314:20)
    at async Promise.all (index 2)
    at async Graph._processModule (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/DeltaBundler/Graph.js:263:5)
    at async Graph._addDependency (/Users/corepyle/Documents/teams/aws-doc-sdk-examples/javascriptv3/example_code/reactnative/ReactNativeApp/node_modules/metro/src/DeltaBundler/Graph.js:314:20)
    at async Promise.all (index 1)
    ```

cpyle0819 added a commit to cpyle0819/aws-doc-sdk-examples that referenced this issue Jul 25, 2023
This updates the @AWS-SDK packages to fix a bug (aws/aws-sdk-js-v3#4631).
Unfortunately, another issue has popped up after these updates. I commented on the above ticket
my findings. As a result, this example is still broken.
beqqrry-aws pushed a commit to cpyle0819/aws-doc-sdk-examples that referenced this issue Jul 31, 2023
This updates the @AWS-SDK packages to fix a bug (aws/aws-sdk-js-v3#4631).
Unfortunately, another issue has popped up after these updates. I commented on the above ticket
my findings. As a result, this example is still broken.
beqqrry-aws pushed a commit to awsdocs/aws-doc-sdk-examples that referenced this issue Jul 31, 2023
shepazon pushed a commit to shepazon/aws-doc-sdk-examples that referenced this issue Aug 7, 2023
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

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 Aug 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p1 This is a high priority issue
Projects
None yet
Development

No branches or pull requests

8 participants