Issue with monorepo architecture ant tRPC

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
K
Kimblis414d ago
one solution to solve this was to define router type with AnyRouter that you export, however then I get this error in my client
K
Kimblis414d ago
N
Nick414d ago
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?
K
Kimblis414d ago
Yeah, it's aliased path, and everything worked before bumping up version
K
Kimblis414d ago
K
Kimblis414d ago
here I set transformer and as for the router I import it in different file and add routes
K
Kimblis414d ago
N
Nick414d ago
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
K
Kimblis414d ago
yeah just tried, didn't do anything :/ Yeah, I'm always reloading extension host and ts server (on vs code)
N
Nick414d ago
Can you try commenting out all your routes in appRouter and just adding one really trivial one? just a hello world query
K
Kimblis414d ago
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
K
Kimblis414d ago
K
Kimblis414d ago
and still get same error 😄
N
Nick414d ago
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?
K
Kimblis414d ago
It's locating in the same one
N
Nick414d ago
What does #content-base/../student-backend/etc do then? Something is looking really weird
N
Nick414d ago
GitHub
The inferred type of "X" cannot be named without a reference to "Y"...
Bug Report 🔎 Search Terms inferred type cannot be named, symlink node_modules 🕗 Version & Regression Information I'm verifying the problem on the typescript@4.1.3. I've not ...
N
Nick414d ago
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
K
Kimblis413d ago
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?
N
Nick413d ago
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
AK
Alex / KATT 🐱413d ago
Might be that superjson isn't added as a dep to all packages Or mismatching versions
K
Kimblis413d ago
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.
N
Nick413d ago
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.
More 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 theHow to manage custom errors (e.g. custom error codes) in tRPC?What's the recommended way to add fields to a TRPCError? How do you make that typesafe also on the ctypesafe 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 querHow to use querykeys from react-queryI am trying to implement a search query to an api that i am fetching via a procedure, i also read on