aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.97k stars 556 forks source link

TypeError: Cannot add property config, object is not extensible at _FetchHttpHandler.handle #5987

Closed prasid444-niural closed 2 months ago

prasid444-niural commented 2 months ago

Checkboxes for prior research

Describe the bug

While uploading a file to s3, it gives Typeerror. But this happens only when I do yarn start and is working correctly in build and serve. This is when using vite, it was working on CRA.

error message:

VM8:1 TypeError: Cannot add property config, object is not extensible
    at _FetchHttpHandler.handle (@aws-sdk_client-s3.js?v=275400b4:6965:19)
    at async @aws-sdk_client-s3.js?v=275400b4:21097:18
    at async @aws-sdk_client-s3.js?v=275400b4:10401:24

SDK version number

@aws-sdk/client-s3@3.470.0

Which JavaScript Runtime is this issue in?

Browser

Details of the browser/Node.js/ReactNative version

Chrome: 123.0.6312.107 Safari: 17.4.1

Reproduction Steps

    try {
      const s3 = await getS3(); //gets new S3Client() 
      const putObjectCommand = new PutObjectCommand({
        Bucket: "",
        Key: "file path",
        Body: file, //file object
      });
      console.log("came here")
      await s3.send( putObjectCommand);
      console.log("not here, above line throw error")
    //should return success i.e new file
    } catch (error) {
      console.log(error); //this gave typeerror
      throw new Error("File upload failed. Removing file.");
    }

Observed Behavior

VM8:1 TypeError: Cannot add property config, object is not extensible
    at _FetchHttpHandler.handle (@aws-sdk_client-s3.js?v=275400b4:6965:19)
    at async @aws-sdk_client-s3.js?v=275400b4:21097:18
    at async @aws-sdk_client-s3.js?v=275400b4:10401:24

It seems the send method is trying to extend the argument provided which failed to extend the property config possibly due to use strict mode.

Expected Behavior

It should not throw any Typeerror and file should be uploaded successfully as it is done in build mode.

Possible Solution

Either the argument should be extensible by default or we may should be able to configure if strict mode should be removed or not [but I guess this should not be done].

Additional Information/Context

No response

prasid444-niural commented 2 months ago

Any updates in this?

aBurmeseDev commented 2 months ago

Hi @prasid444-niural - thanks for reaching out.

I tried to reproduce it with code snippet below, similar to yours but was unable to. I noticed you mentioned that this only occurs when using Vite. Can you share necessary steps to reproduce with Vite? Also I can't tell as your code snippet is incomplete, can you verify how you're configuring your credentials, region and such?

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

try {
const client = new S3Client({
    region: "us-west-1"
});
const putObjectCommand = new PutObjectCommand({
    Bucket: "uploadtest",
    Body: "test.xml",
    Key: "test.xml",
})

await client.send(putObjectCommand);
} catch (error) {
    console.log(error)
}

Best, John

github-actions[bot] commented 2 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 1 month 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.