Server and client environment variables are being loaded from different .env files.
Hello, I'm working on tanstack/start app in monorepo. I also configured
/src/
directory to better organize the files. The issue is that server environment variables (from process.env
) are being loaded from web/src/.env
, while the client variables (from import.meta.env
) are being loaded from web/.env
.
I found that I can set vite.envDir
in app.config.ts
. I can technically use this to solve my issue, but the .env
file would have to live in /web/src
. This is not ideal. Instead I'd like the .env
file to live in /web
. But I couldn't find any way to set path for server envs.
Is there way to set which file the server envs are loaded from? Or possibly, is there any other solution to my issue?2 Replies
sensitive-blueOP•6mo ago
The whole file structure looks like this:
My app config:
My tsconfig:
absent-sapphire•5mo ago
Did you find a solution?
In my case
import.meta.env
is picked from .env.local
but process.env
is picked from .env