Using zod to parse environment
In the docs there is a runtime validation example in https://tanstack.com/start/latest/docs/framework/react/environment-variables#runtime-validation
I'm struggling to get this to work as this file end up getting included in the client and the serverEnv parse produces and error.
I'e tried a couple of things
* splitting into different files - but it ends up being included anyway
But I feel like this will impact performance as throughout the code I'll be using serverEnv() everywhere so it's always reparsing.
What's the "right" pattern here?
Environment Variables | TanStack Start React Docs
Learn how to securely configure and use environment variables in your TanStack Start application across different contexts (server functions, client code, and build processes). Quick Start TanStack St...
3 Replies
vicious-gold•11h ago
Env
Never build your apps with invalid environment variables again. Validate and transform your environment with the full power of Zod.
vicious-gold•11h ago
firm-tan•8h ago
I am using
createIsomorphicFn()
for environment variables.
So basically
So I am always using the correct environment no matter what. But this does need strict undefined/null handling though.