I’m using Netlify to host my website built with Svelte.
I have a local .env file where I store environment variables. I want to have access to these variables on the client-side on the production website. I added them in the Netlify dashboard (“Build and deploy” > “Environment”) but still, I don’t have access to it.
Am I missing something? Is there any special command/configuration to do?
Are the values set in process in general. console.log(process.env.YOUR_KEY) in a build script to verify the values are non null
If the value aren’t being read from process.env but instead from a non existent .env file, you could write out the process.env variables in the Netlify build into a .env file in a prebuild step (when running in Netlify CI)
I already added my environment variable in the Netlify UI. But even though I set the variable in the UI, it is not taken into account and once the site is built and deployed, the variable is not present in process.env.
I’m looking for a way to access my env variable on the production website. Is it mandatory to push the .env file to my GitHub repository?
There is more information about the latter here:
If this is a Function not having the environment variable, please let us know which function this is happening for.