Next.js Discord

Discord Forum

Ensuring .env files are set

Answered
Horned oak gall posted this in #help-forum
Open in Discord
Horned oak gallOP
How do I ensure the prescence of .env files?
For example, when I run npm run dev, it simply start next.js but my app requires .env to be set
The situation is worse when I npm run build, no warnings no nothing and it just builds without .env file.
Answered by LuisLl
You could check the .env file against a Zod schema to throw errors if the env vars aren’t defined or don’t match the validation. I believe that’s essentially what a package like this one does
https://github.com/t3-oss/t3-env
View full answer

1 Reply

You could check the .env file against a Zod schema to throw errors if the env vars aren’t defined or don’t match the validation. I believe that’s essentially what a package like this one does
https://github.com/t3-oss/t3-env
Answer