runtimeEnv property in env.mjs in create-t3-app

Hey all, Was playing around entering some vars in the .env file and noticed that my app was building fine and using these new variables even though I hadn't added these vars to the env.mjs file. Upon further reading it looks like the server: property in here is more of a safeguard to make sure you don't accidentally miss out env vars when building which is pretty neat 👍 I read the code comment for the runtimeEnv: property but couldn't quite make sense of it:
/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
* middlewares) or client-side so we need to destruct manually.
*/
/**
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
* middlewares) or client-side so we need to destruct manually.
*/
I didn't add my env variable to runtimeEnv either and things still seemed to work so just trying to figure out the importance of this and when it matters. Thanks!
4 Replies
Sybatron
Sybatron2y ago
so you dont have any variables in runtimeEnv ?
epsilon42
epsilon42OP2y ago
I have these ones:
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
But I also added nodemailer and specified EMAIL_SERVER and EMAIL_FROM in the .env and it seems to be working fine.
Sybatron
Sybatron2y ago
it wont give an error if you dont require them in example server or client anything in them you need in runtimeEnv
epsilon42
epsilon42OP2y ago
ah ok... i guess i'm not really sure on how nodemailer is able to access the variables in the .env though? what sets it apart?
Want results from more Discord servers?
Add your server