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

TypeError: (0, import_protocols.resolvedPath) is not a function error when using release build in android #6656

Closed
4 tasks done
saifalitai opened this issue Nov 13, 2024 · 7 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@saifalitai
Copy link

saifalitai commented Nov 13, 2024

Checkboxes for prior research

Describe the bug

I am encountering an error when trying to use the @aws-sdk/client-s3 package within a React Native project. The error seems to occur due to a missing or incompatible function import_protocols.resolvedPath. This issue prevents me from successfully uploading files to S3 from my React Native application.

### Code Sample:

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import RNFS from "react-native-fs";

const uploadFileToS3 = async (filePath) => {
  const s3Keys = {
    region: "us-west-2",
    s3Bucket: "my-bucket",
    key: "YOUR_ACCESS_KEY",
    sKey: "YOUR_SECRET_KEY",
  };
  const s3Client = new S3Client({
    region: s3Keys.region,
    credentials: {
      accessKeyId: s3Keys.key,
      secretAccessKey: s3Keys.sKey,
    },
  });

  const content = await RNFS.readFile(filePath, 'ascii');
  const uploadParams = {
    Bucket: s3Keys.s3Bucket,
    Key: "path/to/file",
    Body: content,
    ContentType: "application/octet-stream",
  };

  try {
    const command = new PutObjectCommand(uploadParams);
    await s3Client.send(command);
  } catch (error) {
    console.error("Upload error:", error);
  }
};

Regression Issue

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

SDK version number

@aws-sdk/package-name@version, ...

Which JavaScript Runtime is this issue in?

React Native

Details of the browser/Node.js/ReactNative version

React Native version: 0.66.5 AWS SDK version: @aws-sdk/client-s3 (version: "3.688.0") Node version: v20.11.0 Platform: Android (34) react: "18.2.0",

Reproduction Steps

  1. Install @aws-sdk/client-s3 in a React Native project.
  2. Configure the S3 client and attempt to upload a file.
  3. Observe the TypeError related to import_protocols.resolvedPath.

Observed Behavior

Here is the exact error message:

TypeError: (0, import_protocols.resolvedPath) is not a function. (In '(0, import_protocols.resolvedPath)(path, _this2.input, memberName, labelValueProvider, uriLabel, isGreedyLabel)', '(0, import_protocols.resolvedPath)' is undefined) at line: 146395, column: 59, sourceURL: 'index.android.bundle'

Expected Behavior

The file should be successfully uploaded to S3 without throwing any errors.

Possible Solution

Updated @aws-sdk/client-s3 to the latest version.
Cleared npm cache and reset React Native bundler cache.
Tried alternative S3 libraries, but prefer to use @aws-sdk/client-s3.
Additional Context: This error appears specifically related to React Native, as similar code works fine in a Node.js environment.

Special not is working debug build on @aws-sdk/client-s3 (version: "3.609.0"). but not worked on release build

Additional Information/Context

Could you please provide guidance on resolving this or recommend a workaround? Thank you for your assistance!

@saifalitai saifalitai added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 13, 2024
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Nov 13, 2024
@dyarfaradj
Copy link

Same issue but with node.js

@princekurt
Copy link

#6626

Reported already here!

@zshzbh zshzbh self-assigned this Nov 13, 2024
@zshzbh
Copy link
Contributor

zshzbh commented Nov 13, 2024

Hey,

Could you please confirm that you have already added additional packages for react native project?

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

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

import { DynamoDB } from "@aws-sdk/client-dynamodb";

Specifically Metro bundler used by react-native, enable Package Exports Support:

https://metrobundler.dev/docs/package-exports/
https://reactnative.dev/blog/2023/06/21/package-exports-support

@zshzbh zshzbh 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 Nov 13, 2024
@zshzbh
Copy link
Contributor

zshzbh commented Nov 13, 2024

Hey @dyarfaradj,

May I know how do you access file system in node.js? I tried to use fs but didn't see any issues.

import {
  S3Client,
  PutObjectCommand,
  CopyObjectCommand
} from "@aws-sdk/client-s3";
// import RNFS from "react-native-fs";
import fs from 'fs/promises';
// Create an S3 client
const config = {
  region: "us-east-1",
  credentials: {
    accessKeyId: "XXX",
    secretAccessKey: "XXXX",
  },
};
const s3 = new S3Client(config);


//const content = await fs.readFile('./test.txt');
    
s3.send(new PutObjectCommand({
	Bucket: "new-bucket-XXX",
	Key: `test_RNFS.txt`,
	Body: content,
  }));

And I do see the file has been uploaded to s3 bucket.

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

dyarfaradj commented Nov 14, 2024

Hey @dyarfaradj,

May I know how do you access file system in node.js? I tried to use fs but didn't see any issues.

import {
  S3Client,
  PutObjectCommand,
  CopyObjectCommand
} from "@aws-sdk/client-s3";
// import RNFS from "react-native-fs";
import fs from 'fs/promises';
// Create an S3 client
const config = {
  region: "us-east-1",
  credentials: {
    accessKeyId: "XXX",
    secretAccessKey: "XXXX",
  },
};
const s3 = new S3Client(config);


//const content = await fs.readFile('./test.txt');
    
s3.send(new PutObjectCommand({
	Bucket: "new-bucket-XXX",
	Key: `test_RNFS.txt`,
	Body: content,
  }));

And I do see the file has been uploaded to s3 bucket.

I use it like this:

var s3params = {
  Bucket: 'blabla-YYYY',
  Key: 'test.zip',
  Body: fs.createReadStream(`${process.cwd()}/.build/test.zip`),
};
s3.putObject(s3params, function (err) {
  if (err) {
    console.error('Error uploading to S3:', err);
    reject(new Error(`Uploading to S3 failed: ${err.message}`));
  } else {
    resolve();
  }
});

@JulianHillworth
Copy link

JulianHillworth commented Nov 14, 2024

Ok team, after spending about 5 hours on this and scowling through multiple package-lock.json files on multiple git histories I uncovered root cause. @smithy/core (sub dependency) an internal library for the AWS SDK updated itself to 2.5.1. from 2.4.8

Workaround until AWS fix.

In your package.json dependencies just put "@smithy/core": "2.4.8" to enforce the last known working version. Error disappears and uploading to s3 recommenced!

@kuhe
Copy link
Contributor

kuhe commented Nov 14, 2024

Closing as duplicate of #6626

@kuhe kuhe closed this as completed Nov 14, 2024
@aws aws locked and limited conversation to collaborators Nov 14, 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. p2 This is a standard 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

6 participants