Skip to content

TypeError: fetch failed - Invalid connection header in Nitro dev middleware #3955

@saagoor

Description

@saagoor

Environment

Description

When running the dev server with pnpm dev, Vite starts successfully but immediately crashes with a TypeError: fetch failed error. The error originates from Nitro's dev middleware and appears to be related to invalid connection headers in undici.

Steps to Reproduce

  1. Run pnpm dev
  2. Vite starts successfully on port 3001
  3. Error occurs immediately after startup

Expected Behavior

The dev server should start and remain running without errors.

Actual Behavior

The dev server crashes immediately after Vite initialization with the following error:

TypeError: fetch failed
    at node:internal/deps/undici/undici:15845:13
    at async nitroDevMiddleware (file:///.../nitro/dist/_build/vite.plugin.mjs:348:18) {
  [cause]: InvalidArgumentError: invalid connection header
      at processHeader (/.../undici/lib/core/request.js:399:13)
      ...
    code: 'UND_ERR_INVALID_ARG'
}

Error Stack Trace

(node:83342) Warning: `--localstorage-file` was provided without a valid path
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/deps/undici/undici:15845
      Error.captureStackTrace(err);
            ^

TypeError: fetch failed
    at node:internal/deps/undici/undici:15845:13
    at async nitroDevMiddleware (file:///Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected][email protected][email protected][email protected]_@[email protected]_jiti@_01a74e4557b203240be7a8b9a02dd23b/node_modules/nitro/dist/_build/vite.plugin.mjs:348:18) {
  [cause]: InvalidArgumentError: invalid connection header
      at processHeader (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/request.js:399:13)
      at new Request (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/request.js:187:11)
      at [dispatch] (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/client.js:299:21)
      at Client.dispatch (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at [dispatch] (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/pool-base.js:157:28)
      at Pool.dispatch (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at [dispatch] (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/agent.js:122:23)
      at Agent.dispatch (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/[email protected]/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at node:internal/deps/undici/undici:12153:55
      at new Promise (<anonymous>) {
    code: 'UND_ERR_INVALID_ARG'
  }
}

Environment

  • OS: macOS (darwin 24.6.0)
  • Node.js Version: v25.2.1
  • Package Manager: pnpm
  • Framework: Tanstack Start
  • Nitro Version: 3.0.1-alpha.1
  • Vite Version: 7.3.0
  • undici Version: 7.16.0 (via Nitro dependencies)

Configuration

vite.config.ts

import { defineConfig } from 'vite'
import { devtools } from '@tanstack/devtools-vite'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import viteReact from '@vitejs/plugin-react'
import viteTsConfigPaths from 'vite-tsconfig-paths'
import tailwindcss from '@tailwindcss/vite'
import { nitro } from 'nitro/vite'

const config = defineConfig({
  plugins: [
    devtools(),
    nitro(),
    viteTsConfigPaths({
      projects: ['./tsconfig.json'],
    }),
    tailwindcss(),
    tanstackStart(),
    viteReact(),
  ],
  server: {
    allowedHosts: true,
  }
})

export default config

Additional Notes

  1. There's also a warning about --localstorage-file being provided without a valid path, though this appears to be separate from the main error.
  2. The error occurs in nitroDevMiddleware at line 348 of vite.plugin.mjs.
  3. The issue seems to be related to how Nitro is handling HTTP requests through undici, specifically with connection headers.
  4. This might be a compatibility issue between Nitro 3.0.1-alpha.1, Node.js v25.2.1, and/or undici 7.16.0.

Possible Related Issues

  • Could be related to Node.js v25.2.1 compatibility with undici
  • Could be a bug in Nitro 3.0.1-alpha.1's dev middleware
  • Could be related to the proxy configuration in the Nitro route rules

Workaround

None found yet. The dev server is currently unusable.

Reproduction

N/A

Describe the bug

N/A

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions