T
TanStack3w ago
national-gold

How to add custom unenv polyfills for cloudflare-module

I struggle using @aws-sdk/client-s3 with cloudflare-module preset. I keep getting the error Error: [unenv] fs.readFile is not implemented yet! at runtime, when I try to upload to/download from an S3 bucket or pre-sign URLs. Does anyone have similar issues when deploying to Cloudflare? Or now how I can add custom polyfills (unenv/node/fs in my case) on top of the default ones? I already tried the following: * Switching from cloudflare-module to cloudflare-pages following the TanStack Start docs for React (I'm using SolidJs) * Aliasing fs and node:fs following the Cloudflare docs:
// fs-polyfill.ts
export * from "unenv/node/fs";
// fs-polyfill.ts
export * from "unenv/node/fs";
// wrangler.jsonc
{
// ...
"alias": {
"fs": "./fs-polyfill",
"node:fs": "./fs-polyfill"
}
}
// wrangler.jsonc
{
// ...
"alias": {
"fs": "./fs-polyfill",
"node:fs": "./fs-polyfill"
}
}
* Aliasing fs and node:fs via resolve.alias in Vite:
// vite.config.ts
export default defineConfig({
// ...
resolve: {
alias: {
fs: "unenv/node/fs",
"node:fs": "unenv/node/fs",
},
},
});
// vite.config.ts
export default defineConfig({
// ...
resolve: {
alias: {
fs: "unenv/node/fs",
"node:fs": "unenv/node/fs",
},
},
});
Unfortunately, nothing worked so far, always getting the same error at runtime.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?