Next.js Discord

Discord Forum

NEXT_PUBLIC urls not showing in console

Answered
Gulf menhaden posted this in #help-forum
Open in Discord
Gulf menhadenOP
I have a simple variable in .env.local

NEXT_PUBLIC_TEST="TEST"

When I console.log this in the browser, I get an empty object.

I see that my .env.local is loaded when I run pnpm dev
Answered by Gulf menhaden
Found the actual solution, I was under the impression that defining a variable in the .env file will OVERWRITE what's in your global system env variables.

I set supabase env variables a while back while testing and it was attempting to read those because I never "unset" the env variable
View full answer

10 Replies

Gulf menhadenOP
Please don't tell me to put "NEXT_PUBLIC" in front, because that is not working. My .env file is at the root of my project
I restarted dev server many many times
My .env.local variables that are NOT prefixed with NEXT_PUBLIC work on the server
Please send help
On the server, the variables that have NEXT_PUBLIC are empty, even though they have values in the file
Gulf menhadenOP
Ok, now I have issue where I see NEXT_PUBLIC_TEST="TEST" but I do not see my NEXT_PUBLIC_SUPABASE_URL variable that's defined below it
Gulf menhadenOP
Well... I "fixed" issue by not using NEXT_PUBLIC_SUPABASE_URL as a variable name.... everytime I attempt to set it, it shows up blank
But any other variable name works.... idk tf why
Thanks for the help discord
Gulf menhadenOP
Found the actual solution, I was under the impression that defining a variable in the .env file will OVERWRITE what's in your global system env variables.

I set supabase env variables a while back while testing and it was attempting to read those because I never "unset" the env variable
Answer