Open saifalitai opened 1 day ago
Same issue but with node.js
https://github.com/aws/aws-sdk-js-v3/issues/6626
Reported already here!
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
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.
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();
}
});
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!
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:
Regression Issue
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
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!