T
TanStack14mo ago
exotic-emerald

Environment variables

What's the intended method to access environment variables in Start in isomorphic code like createRouter? (import.meta as any).env.VITE_MY_URL works on the client and server and import.meta.MY_URL and process.env.VITE_MY_URL don't.
13 Replies
wise-white
wise-white13mo ago
@Maintainer - Router we need to build a solution for type safe env vars like Astro. I believe nitro handles the compatibility to all of the hosting providers.
foreign-sapphire
foreign-sapphire13mo ago
Docs
Using environment variables
Learn how to use environment variables in an Astro project.
foreign-sapphire
foreign-sapphire13mo ago
manually defining an env.d.ts?
wise-white
wise-white13mo ago
Yep. We basically need to clone that page and functionality import.meta.env is where stuff will live. Not process. (AFAIK) @ballingt I would refer to astros docs and if something there doesn’t work in Start, then file an issue
passive-yellow
passive-yellow13mo ago
Integrate with t3-env?
wise-white
wise-white13mo ago
What’s that?
vicious-gold
vicious-gold13mo ago
GitHub
GitHub - t3-oss/t3-env
Contribute to t3-oss/t3-env development by creating an account on GitHub.
vicious-gold
vicious-gold13mo ago
tl;dr, zod wrapper for env vars that validates at build and runtime
wise-white
wise-white13mo ago
That’s cool
loud-coral
loud-coral13mo ago
I've been trying
console.log("env", import.meta.env.CLERK_HERMES_SIGN_IN_URL);
console.log("env2", process.env.HERMES_BACKEND_URL);
console.log("env", import.meta.env.CLERK_HERMES_SIGN_IN_URL);
console.log("env2", process.env.HERMES_BACKEND_URL);
And they both come back as undefined in a beforeLoad on a router file - not sure if that's a start issue.
extended-salmon
extended-salmon12mo ago
GitHub
Allow type safe access to env (+ show nice errors on .env not set...
There is Discord thread regarding this feature request too but it got forgotten about thus opening discussion/issue here. Essentially it would be great to have type safe access to the env. Similar ...
extended-salmon
extended-salmon12mo ago
opened issue regarding above feature request I do want type safe env access too a lot as I was bit by not having it just now
ambitious-aqua
ambitious-aqua12mo ago
you can add it yourself easily in your project

Did you find this page helpful?