Cannot access 't' before initialization
Hi,
I'm migrating my app to a mono repo but I just can't get past this error for some reason
Cannot access 't' before initialization
when using the tRPC instance anywhere be it a middleware or router
The server is a standalone node server
useAuthenticaton.ts
api.ts
12 Replies
You could try exporting aliases of the functions? like this?
Then maybe you will keep the reference of
t
in the one fileTurns out I can't define middlewares in a separate file, moving them under the api.ts solved the issue for me
You can do this
and create folders to house scoped procedures
this is
procedures.ts
Interesting, I might try this, wasted so much time on this already haha
I have too, so I am happy to share what I've learned
I posted my own discussion here if you want to check it out https://discord.com/channels/867764511159091230/1111426709519093840
I used it to have a bunch of different, service-specific, scoped procedures that have the proper clients attached
asanaProcedure
, salesforceProcedure
, etc..My router is insanely huge
I don't have subrouters instead a route file that has multiple procedures
Was trying your approach to middleware doesn't seem like it would work for chaining multiple middlewares
Came with a new solution, this passes the tRPC instance as a parameter to the middleware and you can still chain multiple middlewares together