-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite: process.env
variables are not working inside loader
#7934
Comments
Adding |
This was an oversight on my part as I misunderstood how Vite handles import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { ConfigEnv, defineConfig, loadEnv } from "vite";
export default ({ mode }: ConfigEnv) => {
// Here we add env vars from .env files to process.env.
// Note the last arg is a blank string so that all env vars
// are loaded, not just those starting with "VITE_"
Object.assign(process.env, loadEnv(mode, process.cwd(), ""));
return defineConfig({
plugins: [
remix(),
// ...etc
],
});
}; |
This has been fixed in #7958 and will be available in the next release. If you'd like, you can update to the latest nightly to get this fix. If you're still having issues, let me know. |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
HI @markdalgleish, upgraded to 2.3.0 and when i run i am not using vite but the regular remix server config as of ^2.0.0 |
@mtin79 Could you share a minimal repro? |
I tried that as well and I still not seeing any process.env variables in my react code. It says: |
You can't access You'll need to send the desired environment variables from your root loader. https://remix.run/docs/en/main/guides/envvars#browser-environment-variables |
Did you manage to make this work? |
Yes they implemented a fix in one of the last versions. See here: vitejs/vite#15173 |
What version of Remix are you using?
2.2.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
Define custom environment variable on .env file:
On root.tsx add loader
Expected Behavior
Server side code should be able to read data from
process.env
. I believe usingimport.meta.env.VITE_TEST
on SSR code reveals that variable to client side code as expected by Vite documentation.Maybe I'm missing something? Or it's a bug?
Actual Behavior
Trying to get any
process.env
variables inside loaders return alwaysundefined
instead.The text was updated successfully, but these errors were encountered: