Solution skill
InvalidArgumentError: invalid upgrade header
Complete solution
Serverless: invalidArgumentError: invalid upgrade header. The verified fix is Fix: [jawj (maintainer)]: In Node there is no global WebSocket, so the driver falls back to the Cloudflare-style fetch-with-upgrade-header method, which fails with 'invalid upgrade header'. Use this when you hit the symptoms above in serverless; not for unrelated serverless errors or general setup questions.
TL;DR
Fix: [jawj (maintainer)]: In Node there is no global WebSocket, so the driver falls back to the Cloudflare-style fetch-with-upgrade-header method, which fails with 'invalid upgrade header'.
The error
Is the connection string the right URL? `invalid upgrade header` sounds like a websocket error, so I'm wondering if I was supposed to use the connection string or maybe a URL for the proxy.Fix
- [jawj (maintainer)]: In Node there is no global WebSocket, so the driver falls back to the Cloudflare-style fetch-with-upgrade-header method, which fails with 'invalid upgrade header'.
Success check: the symptom above is gone and the original operation completes.
When to use
- You hit this exact symptom in serverless.
- You want the verified fix without digging through the thread.
When not to use
- A different error in serverless, even a similar-looking one.
- General serverless setup or credential questions.
Compatibility
- Serverless (neondatabase/serverless)
Variant phrasings
- How to fix "invalidArgumentError: invalid upgrade header" in serverless
- serverless: invalidArgumentError: invalid upgrade header
Source
- https://github.com/neondatabase/serverless/issues/7
Evidence
Asked in gh:neondatabase/serverless#7 (https://github.com/neondatabase/serverless/issues/7): InvalidArgumentError: invalid upgrade header. The issue report: Issue neondatabase/serverless#7 (closed, 6 comments): ## Steps to reproduce
- clone https://github.com/bbigras/test-qwik-neon
- npm install
- replace "fake url" in
src/routes/index.tsxby the connection string from neon.tech (ex:postgres://[email redacted]/neondb) - npm run dev
- access YOUR_HOST
Is the connection string the right URL? invalid upgrade header sounds like a websocket error, so I'm wondering if I was supposed to use the connection string or maybe a URL for the proxy.
Expected result
Actual result
node:internal/deps/undici/undici:14152
Error.captureStackTrace(err, this); The verified answer: [jawj (maintainer)]: In Node there is no global WebSocket, so the driver falls back to the Cloudflare-style fetch-with-upgrade-header method, which fails with 'invalid upgrade header'. Fix: supply a WebSocket constructor - `neonConfig.webSocketConstructor = ws` (the `ws` package). Side note: forgetting the password in the connection string produced a cryptic error; newer driver versions emit a helpful message for that.By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_6wwgZPLtYn64YiIlUZVs7Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">InvalidArgumentError: invalid upgrade header <span>— Vectle</span></a>