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:
I worked around this by upgrading my API server to process it in under 10s, so this confirms it's a timeout issue.
Jump to solution
7 Replies
Codex
Codex9mo ago
It might be that vercel is timing out if you don't have the pro version
Mocha
Mocha9mo ago
I pay for Pro
Bumble
Bumble8mo ago
maybe it has something to do with your middleware file?
Mocha
Mocha8mo ago
I haven't made any modifications to my trpc.ts file (Pages router)
Bumble
Bumble8mo ago
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.
Mocha
Mocha8mo ago
Right, but I don't have a middleware.ts in this project since I'm using Pages Router, not App Router
Solution
Mocha
Mocha8mo ago
I worked around this by upgrading my API server to process it in under 10s, so this confirms it's a timeout issue.
Want results from more Discord servers?
Add your server