TypeError: fetch failed / 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH' #55410
-
SummaryI'm having an issue with one of my API routes. When querying the API from Postman it returns Internal Server Error. I found a related issue, that now has been closed and resolved with a PR. It seems to have been a bug on Next.js side. I have the latest version of Next.js running (13.4.19) and I already tried reproducing the error in an isolated enviroment with a very simple test API, and I get the same error in the terminal. This is the API ` export async function handler(req, res) {
} catch (error) { and this is what I get in the console
API testing with postman keeps returning 500 - Internal Server Error. I honestly am at a loss of what I can do. Additional informationOperating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020
Binaries:
Node: 20.6.1
npm: 9.8.1
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 13.4.19
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Next.js Config:
output: N/A ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
You are using API routes in Pages Router right? Are you doing |
Beta Was this translation helpful? Give feedback.
-
I am using the app dir. My folder structure is src > app > api > test > route.js I tried adding default in the export default async GET(){} but it's still not working and getting the same error. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi I was able to resolve this by switching from fetch to axios. For those who might not have heard of axios - it's a drop-in replacement for fetch. NextJS App router wraps fetch, and UNDICI is what fetch is NextJS calls fetch (which is in your error message), so to help isolate the issue, I switched to a different HTTP client and it worked. Doesn't have to be axios btw, many http clients exists: 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 |
Beta Was this translation helpful? Give feedback.
-
I got the same error code, I have a router app/[...proxy], the request.headers forward to another private API. next@13.4.13
|
Beta Was this translation helpful? Give feedback.
-
putting www in the url fixed it for me on node. e.g. |
Beta Was this translation helpful? Give feedback.
Issue was related to the API returning a BigInt. Implemented a function that takes the result of the API with the BigInd id, and transforms any BigInt value into a string.
API now works from Postman and return correct result.