Unable to use @aws-sdk/client-s3 in Nuxt 3 Pages

I have a new Nuxt 3.6.1 application deployed with cloudflare-pages and everything works as expected. When using @aws-sdk/client-s3 and creating a new s3client the deployment to cloudflare-pages fails after the build and upload is already completed: ✨ Upload complete! Success: Assets published! Error: Failed to publish your Function. Got error: Uncaught TypeError: Cannot convert object to primitive value at functionsWorker-0.18438961492783257.js:20415:77 in e2.defaultUserAgent at functionsWorker-0.18438961492783257.js:22815:340 in Ry.getRuntimeConfig at functionsWorker-0.18438961492783257.js:22820:44 in S3Client at functionsWorker-0.18438961492783257.js:30336:1 Building the application on my local machine works. I also made sure to use the same nitro preset and node version 18.17.0
8 Replies
fantuci
fantuci15mo ago
any updates? i'm having a similar error, trying to find a way to somehow debug this
James
James15mo ago
Does anyone have a minimal repro for this? This is likely caused by something being turned into a Proxy in a dependency. I'm happy to poke more if someone can provide a basic repro repo.
keko92
keko9215mo ago
Thanks @cherryjimbo for the support. In my case it is a freshly created Nuxt 3.6.5 project with an api route initalizing a new S3Client: I can get my deployment working when I move the initializing of the s3Client into the "defineEventHandler" . But then I am getting the "Cannot convert object to primitive value" error when calling the api route.
import { S3Client } from "@aws-sdk/client-s3";

const s3Client = new S3Client({
region: "eu-central-1",
endpoint: "",
forcePathStyle: true,
credentials: {
accessKeyId: "",
secretAccessKey: "",
},
});

export default defineEventHandler(async (event) => {
return {
hello: "world",
};
});
import { S3Client } from "@aws-sdk/client-s3";

const s3Client = new S3Client({
region: "eu-central-1",
endpoint: "",
forcePathStyle: true,
credentials: {
accessKeyId: "",
secretAccessKey: "",
},
});

export default defineEventHandler(async (event) => {
return {
hello: "world",
};
});
keko92
keko9215mo ago
@cherryjimbo aditionaly I created this Nuxt 3 starter repository which produces the same error: https://github.com/FISCHKE/cloudflare-pages
GitHub
GitHub - FISCHKE/cloudflare-pages
Contribute to FISCHKE/cloudflare-pages development by creating an account on GitHub.
keko92
keko9215mo ago
Are the provided exmaples enough to reproduce the problem or do you need additional information @cherryjimbo ? If it helps here is the deployment id: adb468ae-806a-484b-8089-866c5e63bd13
James
James15mo ago
I'm afraid I've not had a chance to look at this yet, sorry
Sylphritz
Sylphritz13mo ago
Any update on this? I'm facing the exact same error when trying to deploy an app that uses @aws-sdk/client-s3 to connect to R2 on Pages
leogargioni
leogargioni7mo ago
@James I'm also having this issue, but not when building, I actually see this in the log streaming. I've added more details on this issue: https://github.com/unjs/nitro/issues/1882#issuecomment-2053895539
GitHub
Preset cloudflare-pages/cloudflare-module not working with @aws-sdk...
Environment Nuxt 3.8.0 with Nitro 2.7.2 vite v4.5.0 Reproduction https://codesandbox.io/p/github/unjs/nitro/csb-z43zd7/draft/tender-wu Run "Nitro Build" Task from the "Run Task or Te...
Want results from more Discord servers?
Add your server