Next.js Discord

Discord Forum

Response.clone: Body has already been consumed

Unanswered
Upland Sandpiper posted this in #help-forum
Open in Discord
Avatar
Upland SandpiperOP
We're seeing the message "TypeError: Response.clone: Body has already been consumed." in lots of fetches, especially during site builds. This is requesting data from multiple backend services. It's not clear why all the responses are already consumed before they should read... Is anyone else seeing this?

4 Replies

Avatar
You can only call res.json() on a response once.

const res = await fetch(…)
await res.json() // works
await res.json() // doesn’t work


.json (or .text, .arrayBuffer, .formData, etc) consumes the body. Once the body has been consumed it cannot be consumed again.

Same for request objects if you are using route handlers. req.json() can only be called once.
Avatar
Upland SandpiperOP
@joulev I get that. My problem is that someone is eating my responses, and I don't know who. i.e. our app has two very standardised functions that call fetch and then transform that to a typed response object. Neither of them have an execution path that would call .json() twice. So it must be something "in the stack" - looking for hints on what that may be.
Avatar
Interesting, could you send an example?
Avatar
fwiw, you can res.clone().json() tho :)
-# assuming you clone before you consume body