Skip to content

POST requests returning non-2xx status crash with "fetch failed" #13013

@Plopix

Description

@Plopix

When using @cloudflare/vite-plugin with Vite dev server, any POST request handler that returns a non-2xx HTTP status code (e.g. 401, 400, 403, 404) causes the Miniflare proxy to crash with a generic fetch failed error. The actual response from the worker is lost and Vite returns a 500 to the client.

GET requests with the same non-2xx status codes work correctly.

NOTE: this is only on DEV (via vite)

Minimal reproduction:

  // app.ts (Hono, but framework doesn't matter)
  import { Hono } from 'hono';

  const app = new Hono();

  // ✅ Works — GET + 401
  app.get('/test-get-401', (c) => c.json({ error: 'Unauthorized' }, 401));

  // ✅ Works — POST + 200
  app.post('/test-post-200', (c) => c.json({ ok: true }, 200));

  // ✅ Works — POST + 201
  app.post('/test-post-201', (c) => c.json({ ok: true }, 201));

  // ❌ Crashes — POST + 401
  app.post('/test-post-401', (c) => c.json({ error: 'Unauthorized' }, 401));

Test commands:

  curl -v http://localhost:5173/test-get-401      # ✅ 401
  curl -v -X POST http://localhost:5173/test-post-200   # ✅ 200
  curl -v -X POST http://localhost:5173/test-post-201   # ✅ 201
  curl -v -X POST http://localhost:5173/test-post-401   # ❌ 500 (should be 401)

Error output in Vite terminal:

  [vite] Internal server error: fetch failed
      at Object.processResponse (node_modules/undici/lib/web/fetch/index.js:237:16)
      ...
      at async _Miniflare.dispatchFetch (node_modules/miniflare/dist/src/index.js:86755:22)
      at async file:///node_modules/@cloudflare/vite-plugin/dist/index.mjs:1601:19

Versions:

  • vite: 8.0.1
  • @cloudflare/vite-plugin: 1.30.0
  • miniflare: 4.20260317.1
  • wrangler: 4.75.0
  • OS: macOS

Pinning Miniflare to this version fixes the issue:

"overrides": {
	  "miniflare": "4.20251217.0"
	},

Metadata

Metadata

Labels

vite-pluginRelating to the `@cloudflare/vite-plugin` package

Type

No fields configured for Bug.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions