T
tRPC

Issue with monorepo architecture ant tRPC

Issue with monorepo architecture ant tRPC

KKimblis3/1/2023
Hi, we had an issue with batched requests that if we batch some requests they produce a TRPCClientError which says Cannot read properties of undefined (reading 'messsage') so I have read that at least error problem was fixed in newer versions, so we tried to update version, but then the builds started to fail. We get this error (photos in the thread) and more information
KKimblis3/1/2023
one solution to solve this was to define router type with AnyRouter that you export, however then I get this error in my client
KKimblis3/1/2023
Nnlucas3/1/2023
Could you share where you’re setting up your transformer on the API? I would focus on fixing the backend errors first, the frontend might give useless errors until the backend itself is compiling ok Putting a # in your import names is something I haven’t seen before though, is that a valid import character?
KKimblis3/1/2023
Yeah, it's aliased path, and everything worked before bumping up version
KKimblis3/1/2023
KKimblis3/1/2023
here I set transformer and as for the router I import it in different file and add routes
KKimblis3/1/2023
Nnlucas3/1/2023
Does your tsconfig for the API have allowSyntheticDefaultImports enabled? Might not affect here, but it's solved many weird issues with default imports for me Also consider reloading your typescript language server (or just window) each time you tweak something, it can just be your editor being broken
KKimblis3/1/2023
yeah just tried, didn't do anything :/ Yeah, I'm always reloading extension host and ts server (on vs code)
Nnlucas3/1/2023
Can you try commenting out all your routes in appRouter and just adding one really trivial one? just a hello world query
KKimblis3/1/2023
and it is weird that one error is mad on superjson since versions between services are literally the same (checked even node_modules), and as for the AnyRoute maybe the type isn't that decent? 😄 Any way to describe router type differently? damn, tried this
KKimblis3/1/2023
KKimblis3/1/2023
and still get same error 😄
Nnlucas3/1/2023
Is TS locating superjson in a different monorepo package than it's being imported from? Are you sure it's actually installed in the package it's being imported into?
KKimblis3/1/2023
It's locating in the same one
Nnlucas3/1/2023
What does #content-base/../student-backend/etc do then? Something is looking really weird Also noticed this comment: https://github.com/microsoft/TypeScript/issues/42873#issuecomment-1435957417 There might be some other suggestions on that page to help It's looking like quite a specific issue to how you're set up
KKimblis3/1/2023
Yeah I was looking into this one this morning, didn't found anything that would help :/ Talking about the route since I'm using clients in my API's to communicate between backend services, maybe it's using that in build but the end of that route is still node_modules of the service that is throwing this issue, so it's using his own superjson UPDATE* If I add import type {} from 'superjson'; on top of every route then it removes these errors at least on vs code, however if I try to build I still get errors, but then with other packages like fastify, fastify types and etc... 😄 So it's a rabbit hole any way to describe routes? Without writing typescript types from scratch? also how much it would impact performance If we would go to older versions and don't use batch requests?
Nnlucas3/1/2023
You’re honestly just doing something very weird in your repo, but without looking at the whole thing I couldn’t tell you exactly what Just those imports in the errors look suspect
AKAlex / KATT 🐱3/1/2023
Might be that superjson isn't added as a dep to all packages Or mismatching versions
KKimblis3/2/2023
Superjson is added in all services and share the same version. As for @Nick Lucas answer, there would be an additional question- if our backend services needs to communicate between themselves, is creating a trpc client a good path? Because this is what I am doing rn, that's why there are these paths.
Nnlucas3/2/2023
So if you want them hosted separately then they’ll each have their own router and a client for each service they want to talk to. If you want them hosted together you should use createCaller to invoke without hitting the network layer It can be a code smell though, beware cyclic dependencies.

Looking for more? Join the community!

T
tRPC

Issue with monorepo architecture ant tRPC

Join Server
Recommended Posts
Using tRPC in CRON jobsHey everyone, this might be a very stupid question, but is it possible to use tRPC inside a CRON joasync createContext for Express AdapterBeen debugging an odd behavior for the past hour, it seems like that an async function does not workIs it possible to split the router definition with the imlementation?I want to define the server router(input\output\meta) in a separate package from the server package Cache not working for `useQuery`I have a query like this: ```js const { data: article, isFetching } = api.public.getArticle.useQueryZod File Upload Validation with Open-Api Support?Hi guys, anyone know how to validate file upload with zod and get also open-api support?Zod validation and open-api support for File on the server?Hi guys, anyone know how to validate a File upload using zod? and also have open-api support?is context cached?If I put an object on the context that represents the User record from my database... ``` export asyJSON inferred router output not matchingHello. I have a procedure query which is returning Json from a postgresql db using Prisma. The type Best way to implement input based validation on a router procedureHi guys, bit of a noob. I have already created a 'protectedProcedure', ensuring the user is logged [Help] Turbo shared typesI have a turborepo with two apps (web and embed). web is a t3 stack and embed is a create-react-app.Cache SSG helper responseI'm using `createProxySSGHelpers` in GSSP with `ssr: false` in the global config. I trying to cacheInput is too big for a single dispatchI decided to try tRPC for my Crypto analytics dashboard. However, I'm having a hard time passing thetypesafe permissionsHi, So I wanted to infer all the procedures from my router recursively & assign a permission (stringawaiting for procedure & logging the response.Hi, I was wondering if there is a way to handle the return object via the post-middleware's? I know createCaller Dependency Injection in Middleware ctx ?`createCaller` makes it really easy to inject dependencies via anything that's created during the `cbest practices for organizing routes/procedures?i'm trying to find some practices/styles in which people generally define routes with trpc. currentlValidating input inside middleware declaration```js const enforceUserIsCreatorOfEvent = t.middleware(({ ctx, next, input }) => { if (!input.evenFetch errors on stale pagesRecently I have been getting a lot of fetch errors on stale pages, in particular ones that have querDistribute typesafe tRPC Client in an NPM libraryHi ! super fan of trpc over here. We are building a javascript sdk for our API that is essentiallyMutation or query for something that updates db, but runs on every app load?I have 2 operations that need to run before showing my app UI. Those operations perform updates in D