Next.js Discord

Discord Forum

How to fix 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH' error

Answered
Orangetailed potter wasp posted this in #help-forum
Open in Discord
Orangetailed potter waspOP
I have my serversideprop() function in my subscription.js file to communicate with internal api in nextJS
The website and server side prop function is working fine when running at localhost:3000
But when I had deployed my website to vercel it was giving 500 internal server error
Then i viewed my server logs and i found out this 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH' error
pls help me with this issue
Answered by Bigeye scad
Hey all, I was able to resole the UND_ERR_REQ_CONTENT_LENGTH_MISMATCH error by switching from fetch to axios.

For a full solution, see here: https://janac.medium.com/nextjs-fails-with-und-err-req-content-length-mismatch-after-redirect-from-server-0acdc0bfb194
View full answer

27 Replies

Orangetailed potter waspOP
here is my code for get serversideprops function
Chinese Egret
Have you set environment variables in vercel?
Orangetailed potter waspOP
yes
i have also tried with the hard coded url in place of process.env.FRONT_IP
but the results were same
Orangetailed potter waspOP
Pls address this issue
Orangetailed potter waspOP
☝🏻
Chinese Egret
Try using try…catch and log the error. Those errors usually comes when the fetch could not leave client or CORS
Check if these could be the cause
@Orangetailed potter wasp did you find a fix?
@Arinji <@1084102138281607248> did you find a fix?
Orangetailed potter waspOP
No not yet
i might have found one
Bigeye scad
@Arinji what was your solution?
@Bigeye scad <@890486507872342027> what was your solution?
Are you fetching your own api?
Bigeye scad
Yeah I am
I'm doing that because I want to make a long running fetch and vercel has a 15s timeout by default
@Bigeye scad I'm doing that because I want to make a long running fetch and vercel has a 15s timeout by default
that won't help, getServerSideProps is also subject to the 15s timeout
if you want a long running process, vercel is unsuitable
@joulev that won't help, `getServerSideProps` is also subject to the 15s timeout
Bigeye scad
Thanks for the response - my goal is to call an A.I. API that takes around 20 - 30 seconds to respond. What would be the best approach if my nextjs app is currently hosted on vercel?
- Get a faster API
- Deploy on somewhere else, I would recommend [Railway](https://railway.app)
You can link it with GitHub like Vercel, there's a free plan and you don't need to add a credit card @Bigeye scad
Even if vercel allowed a longer timeout than 20 seconds, that’s still too long for you to keep any users at all
Bigeye scad
Hey all, I was able to resole the UND_ERR_REQ_CONTENT_LENGTH_MISMATCH error by switching from fetch to axios.

For a full solution, see here: https://janac.medium.com/nextjs-fails-with-und-err-req-content-length-mismatch-after-redirect-from-server-0acdc0bfb194
Answer