input needs to be an object when doing a batch call?
Hey folks, just setup tRPC and running into the above error when trying to run mutations. Queries, even with inputs, work fine. Am I doing something wrong?
15 Replies
If I look at the request, it's a POST request with a
?batch=1
query param. The body is {"0":{"foo":"bar"}}
This all looks fine
Could you show the exact error? And share any more complete code?
Stripping out the gist of the code for an example often seems helpful but when it's likely to be a coding mistake it actually hides useful information from us
The above is copy pasted verbatim, except that the
mutateAsync
call happens in an onClick
handler...
Full(er) error:
Maybe it has to do with the way my server is setup...Could be, weβre into some weeds that Iβm not too familiar with here
All good, I think it might be my server setup. It's a bit unusual. Thanks for the help!
Might be worth trying one of the example/starter projects and bringing over some work to or from it. Would give you a basis for comparison at least!
Maybe someone else here recognises the issue though, good luck!
The body that's coming in from my server is of 0 length so looks like that's the problem π
Thanks again!
I'm facing this issue with nextjs and have no idea how to resolve it. any ideas ?


input body is indeed an object.
logging the req.body in trpc middleware logs
{"0":{"json":{"phone":"123456789"}}}

removing
"Content-Type": "application/json",
from the headers fixed the issue.seem to be related to this line in trpc repo.
https://github.com/trpc/trpc/blob/eaaff36b86e2c172524fafe1f394088cc4fd9c00/packages/server/src/adapters/fetch/fetchRequestHandler.ts#L60C5-L62C10
GitHub
trpc/packages/server/src/adapters/fetch/fetchRequestHandler.ts at e...
π§ββοΈ Move Fast and Break Nothing. End-to-end typesafe APIs made easy. - trpc/trpc
Probably worth opening an issue with a reproduction if you could?