I am trying to test run a cloudflare worker locally using wrangler dev
(although I have the same issue when running npm start
), and I keep getting an EPIPE error. The error message and code are below. I am on Ubunutu 22.04 if that is relevant. Is this a bug I should report (and, if so, to which project?), or am I doing something wrong?
Error
username@machine:~/worker$ wrangler dev
โ
๏ธ wrangler 3.0.0
------------------
wrangler dev now uses local mode by default, powered by ๐ฅ Miniflare and ๐ท workerd.
To run an edge preview session for your Worker, use wrangler dev --remote
Using vars defined in .dev.vars
Your worker has access to the following bindings:
- R2 Buckets:
- R2_BUCKET: bucket
โ Starting local server...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-05-12",
but you've requested "2023-05-18". Falling back to "2023-05-12"...
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
/home/username/.nvm/versions/node/v20.1.0/lib/node_modules/wrangler/wrangler-dist/cli.js:30632
throw a;
^
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:946:11)
at Socket._write (node:net:958:8)
at writeOrBuffer (node:internal/streams/writable:399:12)
at _write (node:internal/streams/writable:340:10)
at Writable.write (node:internal/streams/writable:344:10)
at Runtime.updateConfig (/home/username/.nvm/versions/node/v20.1.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:5120:26)
at async #assembleAndUpdateConfig (/home/username/.nvm/versions/node/v20.1.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:9130:23)
at async #init (/home/username/.nvm/versions/node/v20.1.0/lib/node_modules/wrangler/node_modules/miniflare/dist/src/index.js:8894:5)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Node.js v20.1.0
Code
import { Router, RouterType, IRequest } from 'itty-router'
export interface Env {
R2_BUCKET: R2Bucket;
}
const router: RouterType = Router();
const get_static = async (req: IRequest, env: Env): Promise<Response> => {
const url = new URL(req.url);
const key = url.pathname.slice(1);
const object = await env.R2_BUCKET.get(key);
if (object == null) {
return new Response('404, not found!', { status: 404 });
}
const headers = new Headers();
object.writeHttpMetadata(headers);
headers.set('etag', object.etag);
return new Response(object.body, { headers });
}
router.all('*', get_static);
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return await router.handle(request, env, ctx);
},
};
I do not get the error when running the hello world worker script, but once I import itty-router
and try to run, the error occurs. I expected the worker to run a local server normally, but the error shown above results instead.