T
tRPC

TRPCClientError: Unexpected end of JSON input

TRPCClientError: Unexpected end of JSON input

Ddocker011/27/2023
Hey I am running into this issue when calling a mutateAsync in production in Vercel (the error does not appear in localhost dev mode).
TRPCClientError: Unexpected end of JSON input
My code base is so large that I am not sure where do I start to debug. Are there any best practices that I should follow to avoid this error? It is similar to this issue: https://github.com/trpc/trpc/discussions/1847#discussioncomment-4244990
Nnlucas1/27/2023
If you inspect the failed request in the network debugger what does it return? I mostly see errors like this where some HTTP service is returning an error in HTML format where it's expected to be a JSON response on the happy path. Could also be some encoding issue though. tRPC itself wouldn't return HTML but perhaps it's just forwarding some error from inside your API?
Ddocker011/27/2023
Here is the header response. The weird part is that if I implement a "retry" on the call, it always succeeds the second time. And on very rare occasions, it succeeds the first time as well. But I prefer if it just does not error out.
Ddocker011/27/2023
^
Nnlucas1/27/2023
What's the body response though?
Ddocker011/27/2023
payload? Im not sure what you are referring to the "network>response" tab is empty
Nnlucas1/27/2023
Got it 500 implies the error originated inside the API itself, not on the client side. Which means it's a likely problem with something you're doing in your own application You should check the logs on the API and add more logging if they're not helping
Ddocker011/27/2023
let me give it a try thanks
Ddocker011/27/2023
I try to add console.log and ran it in prod. For some reason console.log does not appear if the error occurs. The error shown in image.
Ddocker011/27/2023
Even when I run a dummy function, it fails (only in Vercel prod).
testFunction: t.procedure.mutation(({ctx})=>{
return {testValue: true: testValue2: 0}
})
testFunction: t.procedure.mutation(({ctx})=>{
return {testValue: true: testValue2: 0}
})
Ddocker011/27/2023
Nnlucas1/27/2023
This definitely looks like a debugging piece within your app. The stacktrace looks quite informative
Ddocker011/27/2023
So even with an empty function, since the error still occurs, so a trpc setup issue? Seems odd as I just ran T3 app.
Nnlucas1/27/2023
You’re hosting within lambda right? I would look at that setup if it’s working locally. Can be in your codebase or in your infrastructure

Looking for more? Join the community!

T
tRPC

TRPCClientError: Unexpected end of JSON input

Join Server
Recommended Posts
Is it ok to use a createCaller() router within ServerSideProps?The official trpc docs shown an example of how to use the SSGHelper router within SSPs. The procedurtRPC Cors Authentication ErrorHey, I was mainly looking to enable CORS locally for calling my tRPC endpoints in localhost:3000 (NeDemo code `trpc.infinitePosts.add` on infinitedQuery not workingDoc here: https://trpc.io/docs/useInfiniteQuery#getinfinitedata, I created an my query like this: ``NextJS + TRPC + NXi have a nextjs application inside a NX monorepo. i have everything for @trpc/server inside a node lGlobal context or shared context.We are using react query and trpc and we ran into a undesired effect I hope someone could help me wiNot sure how to troubleshoot `Failed to fetch at Function.from`Am getting this on a trpc mutation in v.9 that is firing successfully then pushing me to the URL witthe tRPC loop or cyclewhat is the full sequesnce of execution of trpc? where does it start when a user requests something tRPC context and NextJSGuys quick question about using trpc and nextjs. I'm using context with trpc to create some queries Hardware IoT APIMaybe it's a wrong place to ask but out of curious: Does anyone have experience building API for harHelp to understand how and when to use tRPC in larger projectsHi! I'm pretty sure the answer to my question is that tRPC is not suitable for this project, but anBest practices on trpc and SentryWe are currently migrating to trpc from Apollo server/graphql. We don't use next. What are the best How to do dependecy injection?My routes are grouped by using the router object. i'd like to be able to inject a service to each roA lot of WHYGreat post from @cje on Twitter but also got a lot of questions 1. If the data flow starts from `How are they defined separately?I am using monorepo for my project design and I want to separate the definition of trpc completely ihow can i get procedure name?is it possible to get procedure name? i would like to append a service to ctx based on procedure namtRPC sockets with reactTrying to make my React app work with socket with minimal server but getting error: "Uncaught TypeE