This works fine for me in a Worker:

This works fine for me in a Worker:
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";

export default {
async fetch(_, env) {
const client = new S3Client({
region: "auto",
endpoint: env.R2_BUCKET_ENDPOINT,
credentials: {
accessKeyId: env.R2_ACCESS_KEY_ID,
secretAccessKey: env.R2_SECRET_ACCESS_KEY,
},
forcePathStyle: true,
});
return Response.json(
await client.send(
new GetObjectCommand({
Bucket: "somebucket",
Key: "somefile",
})
)
);
},
};
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";

export default {
async fetch(_, env) {
const client = new S3Client({
region: "auto",
endpoint: env.R2_BUCKET_ENDPOINT,
credentials: {
accessKeyId: env.R2_ACCESS_KEY_ID,
secretAccessKey: env.R2_SECRET_ACCESS_KEY,
},
forcePathStyle: true,
});
return Response.json(
await client.send(
new GetObjectCommand({
Bucket: "somebucket",
Key: "somefile",
})
)
);
},
};
What exactly are you running?
7 Replies
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Hard@Work
Hard@WorkOP5mo ago
Firstly, are you using a framework that populates process.env for you? Since it isn't available globally by default
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Hard@Work
Hard@WorkOP5mo ago
Ok, I think I see it... Nitro does some lifting to add node-compatibility to the code you write(even if you deploy to non-Node environments, like Workers/Pages). The trouble is, it is doing just enough that the S3 SDK thinks it is running in Node, then it relies on packages that only exist on Node.
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Hard@Work
Hard@WorkOP5mo ago
Disable some of their polyfills, if possible? Otherwise, maybe a framework that doesn't do as much lifting? You could also try reporting the issue to the Nitro Developers? I don't have experience with the internals of Nitro, so maybe they might know more about how to get it working
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server