❌ Attempted to access a server-side environment variable on the client get's thrown in db.ts
Hi, I get a weird error in my nextjs application created with create-t3-app.
It throws an error that a server-side environment variable get's accessed clientside in db.ts even tho db. should never be executed clientside.
This is my env.mjs:
7 Replies
You're most likely importing and using something on the client side by mistake. Check for all places that import db
That was the problem.
I created a Schema in one of the TRPC Routers and imported it client side
Is it possible to define a "shape" once and use it for both TRPC Router and client ?
You export the tRPC router type and use that on the client. Thats how tRPC is setup
If you want the type for a specific route use the route helpers
Inferring Types | tRPC
It is often useful to access the types of your API within your clients. For this purpose, you are able to infer the types contained in your AppRouter.
importing schema clientside is ok
they just cant be in the same file as "actual server code"
personally if i need to share schema, i break the file into
someRouter.ts
and someRouter.schema.ts
you can put them anywhere of course, but next to the router makes the most sense to me personallyusing process.env instead of importing the env object worked for me