vercel/next.js · error
A body was attempted to be set with a 204 statusCode for ${r
Error message
A body was attempted to be set with a 204 statusCode for ${req.url}, this is invalid and the body was ignored.\nSee more info here https://nextjs.org/docs/messages/invalid-api-status-body What it means
Error "A body was attempted to be set with a 204 statusCode for ${req.url}, this is invalid and the body was ignored.\nSee more info here https://nextjs.org/docs/messages/invalid-api-status-body" thrown in vercel/next.js.
Source
Thrown at packages/next/src/server/api-utils/node/api-resolver.ts:71
* Send `any` body to response
* @param req request object
* @param res response object
* @param body of response
*/
function sendData(req: NextApiRequest, res: NextApiResponse, body: any): void {
if (body === null || body === undefined) {
res.end()
return
}
// strip irrelevant headers/body
if (res.statusCode === 204 || res.statusCode === 304) {
res.removeHeader('Content-Type')
res.removeHeader('Content-Length')
res.removeHeader('Transfer-Encoding')
if (process.env.NODE_ENV === 'development' && body) {
console.warn(
`A body was attempted to be set with a 204 statusCode for ${req.url}, this is invalid and the body was ignored.\n` +
`See more info here https://nextjs.org/docs/messages/invalid-api-status-body`
)
}
res.end()
return
}
const contentType = res.getHeader('Content-Type')
if (body instanceof Stream) {
if (!contentType) {
res.setHeader('Content-Type', 'application/octet-stream')
}
body.pipe(res)
return
}
View on GitHub (pinned to 0eb3775416)
Solutions
- Do not send a body with a 204 status code; use `res.status(204).end()` without a payload.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/next/src/server/api-utils/node/api-resolver.ts:71 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19).
Data as JSON: /api/errors/cc7af36e5c9729bf.
Report an issue: GitHub.