So I just started to create my first API route, and immediately I'm running into issues. Looking trough Google and this Discord, I only found one similar issue, but that should have been solved in the latest stable version.
To reproduce:
Create a file /src/app/api/route.tsx:
export async function GET() {}
Then call it with Postman, adding a body through form-data or by entering a JSON in the raw tab.
The console will return something like this:
TypeError: fetch failed
at Object.fetch (F:\Programming\Github\Navis\node_modules\next\dist\compiled\undici\index.js:1:26669)
at async invokeRequest (F:\Programming\Github\Navis\node_modules\next\dist\server\lib\server-ipc\invoke-request.js:17:12)
at async invokeRender (F:\Programming\Github\Navis\node_modules\next\dist\server\lib\router-server.js:254:29)
at async requestHandler (F:\Programming\Github\Navis\node_modules\next\dist\server\lib\router-server.js:475:24)
at async Server.<anonymous> (F:\Programming\Github\Navis\node_modules\next\dist\server\lib\start-server.js:117:13) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
at write (F:\Programming\Github\Navis\node_modules\next\dist\compiled\undici\index.js:1:67105)
at _resume (F:\Programming\Github\Navis\node_modules\next\dist\compiled\undici\index.js:1:66726)
at resume (F:\Programming\Github\Navis\node_modules\next\dist\compiled\undici\index.js:1:65413)
at connect (F:\Programming\Github\Navis\node_modules\next\dist\compiled\undici\index.js:1:65301) {
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}
Removing the body changes the error to:
- error TypeError: Cannot read properties of undefined (reading 'headers')
at eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:266:61)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
The only thing similar I found on the Github is this issue: Using Undici as node fetch polyfill causes fetch failed
That issue should have been solved according to PR 53843
Now I just updated to next 13.4.19, and I'm still having the issue.
Can someone tell me what I'm doing wrong, and if this is the same bug or not (and if so, should I open a new issue on Github?)