TRPCClientError: Unexpected token 'A', "An error o"... is not valid JSON
I'm making a
fetch
API call to an external server inside a tRPC route.
It works perfectly on localhost, but never works when deployed on Vercel.
The request normally takes ~30s, and it has a large body (~12KB).Solution:Jump to solution
I worked around this by upgrading my API server to process it in under 10s, so this confirms it's a timeout issue.
7 Replies
It might be that vercel is timing out if you don't have the pro version
I pay for Pro
maybe it has something to do with your middleware file?
I haven't made any modifications to my
trpc.ts
file (Pages router)I meant
middleware.ts
at the root of your project. Make sure the request actually gets to your trpc handler. When I got this error, middleware.ts
was redirecting requests to sign in page.Right, but I don't have a
middleware.ts
in this project since I'm using Pages Router, not App RouterSolution
I worked around this by upgrading my API server to process it in under 10s, so this confirms it's a timeout issue.