Errors while running mutations when deploying CT3A using SST
I'm currently migrating a NextJS project of mine from Vercel to SST. It's based of CT3A and the trpc setup is the same as in a fresh CT3A. I was also able to reproduce the error with a fresh CT3A Project.
The error occurs when running mutations.
TRPCClientError: Cannot read properties of undefined (reading 'resolve')
The code for this, afaik runs in aws lambda.
Maybe anyone has an idea?
Solution:Jump to solution
Resolved this, Solution is enabling streaming since ct3a uses the httpBatchStream link
10 Replies
Another thing I found, the request made actually returns a 200 with the correct response object but there are some random characters in between
Are you using superjson on both the server and client? Looks like maybe a serialization issue between server/client?
yeah using superjson in both, also tried upgrading the package, without success
Solution
Resolved this, Solution is enabling streaming since ct3a uses the httpBatchStream link
Hey @NotLuksus - I'm facing similar issue here, i'm somewhat new to development coming from devops. Do you think you can little bit more details on
httpBatchStream
?you can read about it here: https://trpc.io/docs/client/links/httpBatchStreamLink
The batch links in trpc are so that instead of having to sent 10 requests to the server it only needs to sent 1.
Streaming means that the responses don't come back all at once when they finished, but start streaming in over time, so if 1 of the requests is really fast it doesnt have to wait for the others to finish
HTTP Batch Stream Link | tRPC
unstable_httpBatchStreamLink is a terminating link that batches an array of individual tRPC operations into a single HTTP request that's sent to a single tRPC procedure (equivalent to httpBatchLink), but doesn't wait for all the responses of the batch to be ready and streams the responses as soon as any data is available.
Thank you for that. I did already have httpBatchStreamLink but with
Do you mind sharing your thoughts and what version of trpc and next you are using?
unstable_
prefix,
here is what I have:
I am using open-next to deploy to AWS, and what was working before suddenly wasn't... and I get the exact same error that you did, unexepcted numerical values in my response but everything else in the backend working fine.Do you mind sharing your thoughts and what version of trpc and next you are using?
Are you using sst?
No, there is awesome guy who wrapped terraform around open-next which I have experience with:
https://github.com/RJPearson94/terraform-aws-open-next
Thank you @NotLuksus I think I did solve the issue or at least got it to a working point.
Replacing that unstable_httpBatchStreamLink with httpBatchLink did the trick. I had missed a crucial part in the TRPC documentation: OFFICIAL DOCS:
unstable_httpBatchStreamLink is a terminating link that batches an array of individual tRPC operations into a single
HTTP request that's sent to a single tRPC procedure (equivalent to httpBatchLink), but doesn't wait for all the responses of the batch to be ready and streams the responses as soon as any data is available.
this might also be related: https://github.com/sst/open-next/issues/328
hmmm im pretty sure you just need to enable streaming on your lambda