Next.js Discord

Discord Forum

response.json() not resolving in vercel for >20kb response body

Unanswered
Standard Chinchilla posted this in #help-forum
Open in Discord
Standard ChinchillaOP
been debugging this all day, closest thing ive come to is reports of this happening on older versions of next and node and supposedly being resolved, but that has not been the case for me.
https://github.com/vercel/next.js/issues/41853

im on next 14.1.1 using app router, node 18 on vercel.

i have an api endpoint that calls a 3rd party api. the response body can often be over 20kb of data.
the response returns with a 200 when i log it straight after the fetch.
when i try to get the response body, it hangs and i hit vercel's timeout.
a dummy version of this code:
const response = await fetch(`${process.env.API_3RD_PARTY_URL}/20kb-endpoint`)
  .then(r => {console.log(r); return r) // logs, status 200
  .then(r => r.json())
  .then(r => {console.log("json() resolved"); return r}) // does not log
  .catch(e => {console.log(e); throw e}) // does not log or throw

this code works just fine on my local returning a single request like this in < 3s, but in my vercel deployments times out every time. i will note the response size of this endpoint is variable, and only fails on those larger ~20kb responses

2 Replies

Standard ChinchillaOP
Still no luck here 😭
Standard ChinchillaOP
foudn something via gpt-help. i had to delte teh content-length header to get my calls to work again. a workaround for sure, but good enough for now
await fetch(...)
    .then(r => { delete r.headers['content-length'];  return r}) 
    .then(r => r.json())