t
tRPC
t
tRPC
Top-level await causing issues in frontend
Original message was deleted
tRPC
Join
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,111
Members
View on Discord
N
Nick
•
3/5/23, 11:40 AM
Why do you need top
-level await in your AppRouter
?
N
Nick
•
3/5/23, 1:36 PM
You should be awaiting that either in createContext or in a middleware and appending to the Context
. The routers themselves shouldn
’t need to be created asynchronously
N
Nick
•
3/5/23, 1:37 PM
Top level await is a big code
-smell in this situation
S
sachin
•
3/5/23, 4:07 PM
sorry I
'm a bit confused how is top level await related to tRPC
?
S
sachin
•
3/5/23, 4:08 PM
your frontend should not be importing any backend code if you use
import type { AppRouter }
import type { AppRouter }
S
sachin
•
3/5/23, 4:10 PM
what
's the error
? where is it coming from
?
S
sachin
•
3/5/23, 4:10 PM
your bundler
?
S
sachin
•
3/5/23, 4:12 PM
can you send the exact error
S
sachin
•
3/5/23, 4:12 PM
also what framework are you using
S
sachin
•
3/5/23, 4:12 PM
most bundlers just skip over
import type
import type
because it
's not supposed to do anything at runtime
S
sachin
•
3/5/23, 4:17 PM
I recommend moving to next
.js or vite then
, create
-react
-app is pretty much dead
S
sachin
•
3/5/23, 4:23 PM
weird
.
.
.maybe a cache issue
S
sachin
•
3/5/23, 4:28 PM
lol thank the javascript gods i guess
import type { AppRouter }
import type { AppRouter }
import type
import type