NextJs not picking up my ENV vars - no changes made

Very strange - haven't touched this part of the code, or done any new npm installs or anything... but after restarting my workstation, im getting the Invalid Env Vars error... I've just added an var called ENV_FILENAME (with the file name of the ENV File it's in) to all the env's on my system and added
if (_serverEnv.success) {
console.log(
`✅ Valid environment variables on server - ${_serverEnv.ENV_FILENAME}`
);
}
if (_serverEnv.success) {
console.log(
`✅ Valid environment variables on server - ${_serverEnv.ENV_FILENAME}`
);
}
the ENV_FILENAME (which i've defined at the top of each env file) is coming back undefined also I've also added this custom thing to my next.config.mjs
console.log(`
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! WELCOME TO T3
!!
!! Node Version: ${process.version} (use 18!)
!! Database: ${db}
!! ENV: ${env.ENV_FILENAME}
!! Your Developer Handle: ${env.DEVELOPER_HANDLE}
!! HOST: ${env.NEXT_PUBLIC_HOST}
!! NGROK: https://${env.NGROK_DOMAIN}
!!
!! Happy Coding!
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`);
console.log(`
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! WELCOME TO T3
!!
!! Node Version: ${process.version} (use 18!)
!! Database: ${db}
!! ENV: ${env.ENV_FILENAME}
!! Your Developer Handle: ${env.DEVELOPER_HANDLE}
!! HOST: ${env.NEXT_PUBLIC_HOST}
!! NGROK: https://${env.NGROK_DOMAIN}
!!
!! Happy Coding!
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`);
and oddly that renders correctly, with .env.local
1 Reply
fotoflo
fotofloOP7mo ago
✅ Valid environment variables on server - undefined well i did the only sensible thing - deleted the folder and resinstalled it and it worked And then i walked away from the dev box for a bit, and came back and it stopped working again! Same error fresh application install Better summary - Hi guys, im using t3 and next 14. t3 stack also has a function where it uses Zod and validates the envirenment variables and moves them to a const called env. I can get it like this: import { env } from "./src/env/server.mjs"; It works. Now in my next.config.mjs i print out a few key properties from the aforementioned env, that works too. I've been working on this app for quite some time - it's in production and running well, making small change... Today i was working on some totally unrelated client side code, and restarted my dev box and the app runs and the prints out the enviment variables as usual from the next.config.mjs, but then it throws a big zod error that all the of the envirnment variables are missing. I stashed any changes, but there's nothing related to that. I pulled the most recent commit from my dev branch to a new directory and pulled the env and reinstalled the deps and the app worked... And then an hour later, the same error popped up again! Anyone seen anything like this before?
Want results from more Discord servers?
Add your server