#Wrangler R2 local emulation

1 messages · Page 1 of 1 (latest)

modern gorge
#

I'm working on a project locally and i cannot get the worker to emulate an R2 bucket locally. It works if I use --remote but I want to be able to just use it locally.

        const timeout = new Promise<Response>((_, reject) => {
            const id = setTimeout(() => {
                clearTimeout(id);
                reject(new Response('Request timed out', { status: 408 }));
            }, 30000); // 30 seconds timeout
        });

        const putOperation = c.env.MY_BUCKET.put(key, data);

        await Promise.race([timeout, putOperation]);

just seem to time out every time locally.

#
binding = 'MY_BUCKET'
bucket_name = 'main'
preview_bucket_name = 'dev'``` is inside my wrangler.toml
dusty valve
#

I'm experiencing this too, while it worked a while back. Looking at the issues more people seem to be running into this:

GitHub

Which Cloudflare product(s) does this pertain to? R2 What version(s) of the tool(s) are you using? 3.3.0 [wrangler] What version of Node are you using? 20.4.0 What operating system are you using? W...

GitHub

Which Cloudflare product(s) does this pertain to? R2, Wrangler core What version(s) of the tool(s) are you using? 3.1.1 What version of Node are you using? 18.16.1 What operating system are you usi...

modern gorge
#

Now that you pointed it out, I do see that the file was successfully pushed to .wrangler folder

#

Do you happen to know of any work-around?

dusty valve
#

I traced it to

$ cat patches/miniflare+3.20230807.0.patch 
diff --git a/node_modules/miniflare/dist/src/index.js b/node_modules/miniflare/dist/src/index.js
index 15b1ffe..fc0dca9 100644
--- a/node_modules/miniflare/dist/src/index.js
+++ b/node_modules/miniflare/dist/src/index.js
@@ -8656,7 +8656,7 @@ var R2Router = class extends Router {
         valueSize,
         metadata
       );
-      return encodeResult(result);
+      return encodeJSONResult(result);
     } else if (metadata.method === "createMultipartUpload") {
       const result = await gateway.createMultipartUpload(
         metadata.object,
dusty valve
#

😢 looks like it was nodejs version related, you can see more details on the pr above but downgrading my nodejs to an LTS version also makes it work

modern gorge
#

thanks for the PR @dusty valve

#

I appreciate it

#

gave me a lot of insight on what is happening

#

i guess we just have to use LTS until Node push their fix