Wrangler R2 local emulation

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.
// Adding a timeout for the put operation
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]);
// Adding a timeout for the put operation
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.
5 Replies
fs0x30
fs0x30ā€¢10mo ago
binding = 'MY_BUCKET'
bucket_name = 'main'
preview_bucket_name = 'dev'
binding = 'MY_BUCKET'
bucket_name = 'main'
preview_bucket_name = 'dev'
is inside my wrangler.toml
rvg
rvgā€¢10mo ago
I'm experiencing this too, while it worked a while back. Looking at the issues more people seem to be running into this: - https://github.com/cloudflare/workers-sdk/issues/3688 - https://github.com/cloudflare/workers-sdk/issues/3679
GitHub
šŸ› BUG: Local R2 .put() hangs while the put operation seems to succe...
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
šŸ› BUG: Unable to write to R2 locally Ā· Issue #3679 Ā· cloudflare/wor...
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...
fs0x30
fs0x30ā€¢10mo ago
Such a shame 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?
rvg
rvgā€¢10mo ago
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,
$ 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,
made a pr in https://github.com/cloudflare/miniflare/pull/654, lets see what the cf folks say šŸ˜¢ 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
fs0x30
fs0x30ā€¢9mo ago
thanks for the PR @rvg 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 @rvg 20.6 node version fixed it