tRPC

T

tRPC

Move Fast & Break Nothing. End-to-end typesafe APIs made easy.

Join

tRPC, NextJS 14, createTRPCProxyClient, How can I globally manage errors?

I want to be able to redirect a user when they become unauthenticated. Someone else mentioned to create some NextJS middleware which makes an api call for the user but then that will make an extra API call for every tRPC request. It feels like there should be someway I can centrally manage errors where if tRPC returns an 'UNAUTHORIZED' error for any procedure I can do a redirect to '/login' I have a monorepo with everything together but the apps will be deployed separately eventually....

next 14 setup error

i got this type error after setting up trpc in next 14.0.4 Property 'createClient' does not exist on type '"The property 'useContext' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'useUtils' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'Provider' in your router collides with a built-in ...'. Property 'createClient' does not exist on type '"The property 'useContext' in your router collides with a built-in method, rename this router or procedure on your backend."'.ts(2339) Loading......

No typesafety after migrating to 11?

Not sure what happened when upgrading from 10 to 11. tried deleting node modules and lock file and reinstalling. I'm using the AWS adapter I notice the .create() is typed as any, and therefore t is any...
No description

is there a way to send a streaming response

I'm not talking about batching multiple requests, but more of a one-way websocket-like channel between the server and client using HTTP streaming.

Error: Tried to access "$types.__endpoint" which is not available at runtime

Hi all! I'm new here, so I hope i'm posting this in the right place. I'm trying to use tRPC using firebase functions, but I keep getting this error everytime I try to start everything up: Error: Tried to access "$types.__endpoint" which is not available at runtime at [blah]/functions/node_modules/@trpc/core/dist/index.js:344:23 ...

trpc output dates are typed as strings and not dates

I'm using superjson as a transformer. When I query my data, it shows that fields that should be dates are typed as strings. How can I get them to be typed as dates?

TRPC v10 to v11 - change logs location

Where can I read the changlogs from v10 to v11? I have seen the migration guide, but no clear list with changes. Migration guide: ...
Solution:
A better writeup will come for release, but it's not out yet 🙂

tRPC won't return route with function, only JSON

Hey all, Why can I go to route 'test' and the 'This is a test!' is being returned, but when I try to go to another router called 'posts' it returns this big error, 404, meaning that it doesn't even exist, right? While the function does exist, what is it exactly looking for what I don't have? Would love to hear from someone! 🙂...
No description

tRPC router won't return, unless it's just json.

Hey all, Why can I go to 'test' and the 'This is a test!' is being returned, but when I try to go to another router it returns this big error, 404, meaning that it doesn't even exist, right? While the function does exist. Would love to hear from someone! 🙂...

How to make trpc output return strings and not dates

I am not using superjson I would like for all of my trpc routes to return dates as strings. However, right now, the types coming from my router show the output as dates. Any idea on how I can get the types to show as strings?...

Cannot read properties of undefined (reading 'input')

login: trpc_1.publicProcedure.input(loginInput).mutation((opts) => __awaiter(void 0, void 0, void 0, function* () { ^ TypeError: Cannot read properties of undefined (reading 'input') ...

Extending the client with "virtual" procedures

I'm hoping to write a virtual mutation which runs on the client and calls some other client-side apis and a different server procedure. I want to distribute my tRPC client with an "upload" procedure which takes in a File as a argument but instead of actually sending that over the wire, I want to call to another RPC to get a singed s3 url, then use that url to upload the file, then finally return a url pointing to the uploaded file. Here's a fake example of what that could look like: ```typescript...

Dynamic Server Usage Error from RSC calls

posted this on the create-t3-app server as well but not quite sure if the issue is T3 or TRPC related. But hoping I can at least get a recommendation from someone here. Essentially, making a TRPC call from any RSC component causes the build process to throw a dynamic server error. The app still appears to build but I am obviously concerned about the health of the project moving forward. I have found a handful of workarounds but they all seem rather hacky. Could anyone offer some advice how to approach this or are people just forcing dynamic rendering at the top of the file and moving on?...
No description

Node 20, NPM: Send form values to DB with tRPC?

Hey all, anyone in here with some tRPC experience? I have been going through YouTube video's and the doc's, it helped me for a lot of things, while still learning and trying to understand what I am actually doing.. When using the tRPC package with Kirimase I am a little overwhelmed with everything that's coming with the package, and that's great, because it looks amazing and a lot of the dirty work already seems to be done for you, this also makes me a bit clueless in the sence that I am not very sure what everything is doing....
No description

Getting type error in v11 when trying to instantiate createTRPCQueryUtils

Type 'CreateTRPCReactBase<CreateRouterInner<RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { allProjects: QueryProcedure<...>; project: QueryProcedure<...>; }>, unknown> & DecoratedProcedureRecord<...>' is not assignable to type '"The property 'query' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'mutation' in your router collides with a built-in method, rename this router or procedure on your backend." | ... 6 more ... | TRPCUntypedClient<...>'.ts(2322)
createUtilityFunctions.d.ts(10, 5): The expected type comes from property 'client' which is declared here on type 'CreateQueryUtilsOptions<AnyRouter>'
Type 'CreateTRPCReactBase<CreateRouterInner<RootConfig<{ ctx: object; meta: object; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { allProjects: QueryProcedure<...>; project: QueryProcedure<...>; }>, unknown> & DecoratedProcedureRecord<...>' is not assignable to type '"The property 'query' in your router collides with a built-in method, rename this router or procedure on your backend." | "The property 'mutation' in your router collides with a built-in method, rename this router or procedure on your backend." | ... 6 more ... | TRPCUntypedClient<...>'.ts(2322)
createUtilityFunctions.d.ts(10, 5): The expected type comes from property 'client' which is declared here on type 'CreateQueryUtilsOptions<AnyRouter>'
...
No description

LoggerLink logging only via server logger in prod

I have a logger link setup as declared in https://trpc.io/docs/client/links/loggerLink#usage ```ts loggerLink({ enabled: (op) =>...

Better error tracing when using TRPC routers

Hi, I'm using a trpc router and noticed that the error trace report is more or less non existent as compared to just nextjs api routes. Can I make trpc behave like this? See images for reference
Solution:
Okay solved it. Turns out I did catch all errors in the api handler, so to get better messages in dev mode, just throwing the error fixes it
No description

client side Validation with ZOD

will trpc validate input on the client before sending it to the server ?

We're having some serious Intellisense performance issues with v10

Hello. We have about ~30ish routers in mergeRouters (we're working on changing this to a namespaced router) but we're having some serious performance issues (10s+ to open Intellisense in VSCode with extensions disabled). We've also confirmed that TypeScript gets slower the more routers we add. Obviously this is expected, but we didn't think we'd run into this issue with 100+ procedures. We thought we'd be facing an issue like this with 2,000+. Any help on this would be appreciated. We'd be happy to send over an NDA and pay for help as well. Although I can always talk through what's going on here on Discord and add some traces if you feel it would be useful. Btw this is in a monorepo configuration. I haven't yet tried isolating the package on its own and testing to see if the performance is any better. It's a very big project that powers our startup. Thanks....

Parsing FormData on trpc

Hi all, I have function to put object on S3 const putObjectToS3 = async (body: FormData) => { ......