Replies: 4 comments 7 replies
-
Vite hides env variables from the client. Normally you wouldn't need to change |
Beta Was this translation helpful? Give feedback.
-
PR opened! |
Beta Was this translation helpful? Give feedback.
-
@Plopix gave the following solution on Discord. import { unstable_vitePlugin as remix } from "@remix-run/dev";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig, loadEnv } from 'vite';
export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd(), '')
process.env = { ...process.env, ...env }
return defineConfig({
plugins: [
remix(),
tsconfigPaths(),
],
});
} |
Beta Was this translation helpful? Give feedback.
-
Hi! Heavy vite user here, what I personally expect its the vite envvars logic to work: https://vitejs.dev/guide/env-and-mode.html So the import.meta.env should pick automatically the stuff from the env files (not completely supported by the current remix), and if you really want to, you can do something like the trick proposed by @jrestall In other words, in the migration guide I expect a chapter saying to migrate from process.env to import.meta.env (and the .env file convention of vite?) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm updating my application to Remix 2.2.0 and in the process of migrating to Vite!
It's been smooth so far, but running into a roadblock: it looks like I can no longer access all of my environment variables server-side via
process.env.*
.After reading this Vite documentation, I got the impression that we should now read environment variables using
import.meta.env.*
instead ofprocess.env.*
. Even when I try to accessimport.meta.env.*
, it only works if I added theVITE_
prefix, which I thought was only needed for client-side code.I didn't catch anything in the Vite Migration Guide regarding updating the way we read environment variables.
Anybody experiencing something similar or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions