TypeError: fetch failed - Invalid connection header in Nitro dev middleware
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
- Domain
- build-system, tooling
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
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
- Run
pnpm dev - Vite starts successfully on port 3001
- 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
- There's also a warning about
--localstorage-filebeing provided without a valid path, though this appears to be separate from the main error. - The error occurs in
nitroDevMiddlewareat line 348 ofvite.plugin.mjs. - The issue seems to be related to how Nitro is handling HTTP requests through undici, specifically with connection headers.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nitrojs/nitro
-
pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug v2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
v2 v3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
v3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
fix(task): add per-request timeout to `devFetch` http.request() call to prevent indefinite hang Openv3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
comp/dashboard P3 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NousResearch/hermes-agent#117722 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·