T
tscircuit3mo ago
Abse

Env files are hard

I tried process.env.VITE_OPENROUTER_API_KEY import.meta.env.VITE_OPENROUTER_API_KEY Bun.env.VITE_OPENROUTER_API_KEY all of them are null
19 Replies
Seve
Seve3mo ago
process.env is all you need there are a couple possible issues what's the name of your env file just .env i assume?
Abse
AbseOP3mo ago
yes
Seve
Seve3mo ago
and how are you starting the server to test, via vite right?
Abse
AbseOP3mo ago
yeah bun start "dev": "bun run build:fake-api && AUTOLOAD_PACKAGES=true vite",
Seve
Seve3mo ago
at the top of vite.config.ts, log the process.env so vite.config.ts in this case is basically the server entrypoint my guess is what's happening is vite doesn't start with bun so the issue is probably we need to do bunx --bun vite ...
Abse
AbseOP3mo ago
it's consoling somthing but not my .env
Abse
AbseOP3mo ago
No description
Seve
Seve3mo ago
that's probably your env with node node -e "console.log(process.env)" i think the --bun flag will probably work
Abse
AbseOP3mo ago
yup it's node env ok let me check like this "dev": "bun run build:fake-api && AUTOLOAD_PACKAGES=true --bun vite",
DTS dist/schema.d.ts 85.17 KB
/usr/bin/bash: line 1: --bun: command not found
error: script "dev" exited with code 127
error: script "start" exited with code 127
DTS dist/schema.d.ts 85.17 KB
/usr/bin/bash: line 1: --bun: command not found
error: script "dev" exited with code 127
error: script "start" exited with code 127
Seve
Seve3mo ago
you need bunx in there
Abse
AbseOP3mo ago
I did it crashed
Seve
Seve3mo ago
hmm ok just add dotenv to the vite config file and that's fine can't make vite run on bun
Abse
AbseOP3mo ago
this is with bunx
No description
Seve
Seve3mo ago
yea i have no idea
Abse
AbseOP3mo ago
@Seve what was the issue that caused this on cli
No description
Abse
AbseOP3mo ago
it's just fixed by adding dotenv to vite config ?
Seve
Seve3mo ago
yes because the vite config isn't loaded when you import @tscircuit/fake-snippets the issue was that dotenv was loaded in an endpoint
Abse
AbseOP3mo ago
ok got it , ty
Seve
Seve3mo ago
ofc

Did you find this page helpful?