How to use updated client env variable value in production app?
I'm using t3 env + trpc for current tanstack app. After build the image for the bun preset. when i run the app in production i'm getting env variable error as shown in images. I'm running app using
bun run .output/server/index.mjs
in production.
How can i pass env variable when i run the bun run .output/server/index.mjs
command and how to actually parse it in trpc routes. Since it server using import.meta.env.VITE_API_URL it not a best option right!!!



8 Replies
like-gold•4mo ago
You'll need to create two separate files for the env, one for client and one for server, i had the same issue but this worked for me

like-gold•4mo ago
for the clien.ts the runtime will be:
runtimeEnv: import.meta.env
other-emeraldOP•4mo ago
Thnx. That actually fixed the issue.
One more question. Do client env variable get hard codded after the build?
i have the the client env variable and build the app with that env variable value. But when i run the production app with the same client env variable but with new value it not using the updated valuse. Still use the same old valuse that used when building app.
rare-sapphire•4mo ago
yeah client variables are baked at build time. for runtime client settings the easiest is something like a serverFn that you call in _root to fetch them from the server
other-emeraldOP•4mo ago
i'm using t3 env so i don't think that can work!!!
sensitive-blue•4mo ago
Or you can do something like this, keeping all in the same file

other-emeraldOP•4mo ago
That issue is fixed but my consent is how to use updated value in client env variable in production app?
sensitive-blue•4mo ago
Something like: