Prod Environment Variables Please

I'm maybe just doing something silly but when i do an npm run dev i can access env variables but not after an npm run build, i made a simple reproduction: - npm create solid => basic => ts app.config.ts:
import { defineConfig } from '@solidjs/start/config'

export default defineConfig({
middleware: './src/middleware.ts',
})
import { defineConfig } from '@solidjs/start/config'

export default defineConfig({
middleware: './src/middleware.ts',
})
middleware.ts:
import { createMiddleware } from '@solidjs/start/middleware'

export default createMiddleware({
async onRequest () {
console.log('process.env.test', process.env.test)
},
})
import { createMiddleware } from '@solidjs/start/middleware'

export default createMiddleware({
async onRequest () {
console.log('process.env.test', process.env.test)
},
})
.env: test=aloha - npm run dev refresh app, see log of env variable - npm run build and then npm run start, refresh app, env variable log is undefined šŸ˜…
3 Replies
Madaxen86
Madaxen86•2w ago
Several possibilities: Here's an easy one. 1. install dotenv-cli pnpm add -D dotenv-cli 2. in package.json change the start command "start": "dotenv vinxi start", ⬆ for secret envs. If it is okay to expose your envs to the client prefix them with VITE_ and access the, with import.meta.env.test
all_is_source_energy
all_is_source_energyOP•2w ago
Suuuper helpful info both of y'all! Totally fixed it! I appreciate you both!

Did you find this page helpful?