ERR_HTTP_HEADERS_SENT
node
http_error
ai_generated
true
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
ID: node/err-http-headers-sent
92%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
Response already sent but code tries to send again. Missing return after res.send().
genericWorkarounds
-
95% success Add return after res.send()/res.json()/res.redirect() to prevent further execution
if (error) { return res.status(400).json({ error }); } -
88% success Check for multiple middleware calling next() and also sending response
Use return after res.send()/res.json() to prevent double-response
Sources: https://expressjs.com/en/guide/writing-middleware.html
Dead Ends
Common approaches that don't work:
-
Add res.headersSent check before every response
75% fail
Doesn't fix the control flow bug — just hides it
-
Wrap in try/catch
80% fail
The error is a logic bug, not an exception to catch
Error Chain
Frequently confused with: