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?
No description
Solution:
Resolved this, Solution is enabling streaming since ct3a uses the httpBatchStream link
Jump to solution
10 Replies
NotLuksus
NotLuksusOP12mo ago
Another thing I found, the request made actually returns a 200 with the correct response object but there are some random characters in between
No description
Endgame1013
Endgame101312mo ago
Are you using superjson on both the server and client? Looks like maybe a serialization issue between server/client?
NotLuksus
NotLuksusOP12mo ago
yeah using superjson in both, also tried upgrading the package, without success
Solution
NotLuksus
NotLuksus12mo ago
Resolved this, Solution is enabling streaming since ct3a uses the httpBatchStream link
Abdul Sharif
Abdul Sharif11mo ago
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 ?
NotLuksus
NotLuksusOP11mo ago
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.
Abdul Sharif
Abdul Sharif11mo ago
Thank you for that. I did already have httpBatchStreamLink but with unstable_ prefix, here is what I have:
"next": "^14.0.3"
"@trpc/client": "^10.43.6",
"@trpc/next": "^10.43.6",
"@trpc/react-query": "^10.43.6",
"@trpc/server": "^10.43.6",
--------------------------------------
unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
return {
cookie: cookies().toString(),
"x-trpc-source": "react",
};
},
}),
"next": "^14.0.3"
"@trpc/client": "^10.43.6",
"@trpc/next": "^10.43.6",
"@trpc/react-query": "^10.43.6",
"@trpc/server": "^10.43.6",
--------------------------------------
unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
return {
cookie: cookies().toString(),
"x-trpc-source": "react",
};
},
}),
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?
NotLuksus
NotLuksusOP11mo ago
Are you using sst?
Abdul Sharif
Abdul Sharif11mo ago
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
NotLuksus
NotLuksusOP11mo ago
hmmm im pretty sure you just need to enable streaming on your lambda
Want results from more Discord servers?
Add your server