From 65258b0c7f1d3d3dc7133b693e82a879780fdbdc Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Mon, 18 Dec 2023 15:49:53 +0900 Subject: [PATCH] fix: fix mismatch Response class --- packages/vite-node-miniflare/src/server/plugin.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/vite-node-miniflare/src/server/plugin.ts b/packages/vite-node-miniflare/src/server/plugin.ts index 14ee73b13..63032ab1e 100644 --- a/packages/vite-node-miniflare/src/server/plugin.ts +++ b/packages/vite-node-miniflare/src/server/plugin.ts @@ -74,14 +74,19 @@ export function vitePluginViteNodeMiniflare(pluginOptions: { await miniflare.ready; } - // workaround typing mismatch between "lib.dom" and "miniflare" + // workaround Request/Response polyfills mismatch and typings mismatch between "lib.dom" and "miniflare" const request = h3.toWebRequest(event) as any as MiniflareRequest; - return miniflare.dispatchFetch(request.url, { + const res = await miniflare.dispatchFetch(request.url, { method: request.method, headers: request.headers, body: request.body, duplex: "half", - }) as any as Response; + }); + return new Response(res.body as any, { + status: res.status, + statusText: res.statusText, + headers: res.headers, + }); }); const app = h3.createApp().use([