Error on fetch with stream in nextjs dev with --experimental-flag #85001
Replies: 1 comment
-
|
Hi @el-frontend 👋 Root cause: fetch(..., { body: file.stream(), duplex: 'half' }) in Chrome requires HTTPS + HTTP/2 (or HTTP/3). Proof: curl -Iv --http2 https://localhost:3000 → ALPN: server accepted http/1.1 (no h2). ✅ **Fix options Caddy (one file, auto h2):** https://localhost:3443 { Run Caddy, start next dev on 3000, then hit https://localhost:3443. NGINX (enable http2): server { ssl_certificate /path/to/localhost.crt; location / { Browse to https://localhost:3443. Chrome will negotiate h2, and request streaming works. Option B — use a runtime that serves h2 directly Run your own small HTTPS http/2 terminator (Node/HTTP2) and proxy to Next, or use a tool that serves dev over h2. The current next dev --experimental-https doesn’t advertise h2. FYI (server side) Your Route Handler should read the stream (Web Streams API) and not buffer: export async function POST(req: Request) { TL;DR: The cert is fine; the issue is no HTTP/2. Terminate TLS with h2 (Caddy/NGINX) in front of Next dev and your streaming upload will work. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi guys, I have a scenario where I need to create a route handler for file uploads and send the request using a stream. Something like this:
The browser blocks the request with the following error: net::ERR_ALPN_NEGOTIATION_FAILED (see image).
I’m running my application with the --experimental-https flag to enable HTTPS so that streaming requests can work with fetch.
When I run:
I get this response:
It looks like the certificate is fine. Any idea what happened here? I’m using Chrome.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions