Guidance on environment variables #147
-
The Remix docs advise on accessing environment variables using the loader functions, but I'm running into a weird issue accessing them. Everything works as intended in dev mode, but it changes when I deploy to Netlify.
gives me this response:
I can access the process object as a whole and pass all its contents, but it passes an empty object for env and undefined for the variable. Does anyone know what I might be missing or have guidance on handling env with this template? Or why I might be experiencing this disconnect. Idk how to inject env into the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I figured it out. Vite uses a different syntax for the environment variables, I also want to continue using process.env instead of the other syntax, so I added it back here, filtering for the
|
Beta Was this translation helpful? Give feedback.
I figured it out. Vite uses a different syntax for the environment variables,
import.meta.env
instead ofprocess.env
. I tried that before and it didn’t work, but the issue is that it requires theVITE_
prefix to expose these variables to the client. I didn’t know that included the loader functions since there was no issues in Remix dev, but I ran into this double gotcha.I also want to continue using process.env instead of the other syntax, so I added it back here, filtering for the
VITE_
prefix: