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

Open
#3,955 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
nodejs, typescript, vite

Research direction

Reproduce the failure with pnpm dev using the versions and vite.config.ts shown in the issue. Start at Nitro's nitroDevMiddleware in vite.plugin.mjs around line 348 and inspect the request that reaches undici. Done means the Vite/Nitro development server starts and remains running without the invalid connection header error.

Written by the indexing model from the issue text.

Description

needs reproduction tanstack v3 vite plugin
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/nitro@3.0.1-alpha.1_lru-cache@11.2.4_rollup@4.54.0_vite@7.3.0_@types+node@22.19.3_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/undici@7.16.0/node_modules/undici/lib/core/request.js:399:13)
      at new Request (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/node_modules/undici/lib/core/request.js:187:11)
      at [dispatch] (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/node_modules/undici/lib/dispatcher/client.js:299:21)
      at Client.dispatch (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at [dispatch] (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/node_modules/undici/lib/dispatcher/pool-base.js:157:28)
      at Pool.dispatch (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/node_modules/undici/lib/dispatcher/dispatcher-base.js:153:29)
      at [dispatch] (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/node_modules/undici/lib/dispatcher/agent.js:122:23)
      at Agent.dispatch (/Users/mhsagor/apps/edushade/website-builder-v2/node_modules/.pnpm/undici@7.16.0/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

Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.