kit: Env variables are not accessed by vite in PROD
Describe the bug
I am using the docker image for the production build. I have set my environment variables in docker and they are accessible by using env
. But when I build the app these are not accessed by Vite.
Please help me here!
Reproduction
Create Svelte kit app by started.
- create the docker image
- Create the env variables in the docker system.
- use the VITE_ as a prefix.
Logs
No response
System Info
Undefined
Severity
blocking all usage of SvelteKit
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 17 (6 by maintainers)
I solved this by building the .env from a shell script, using a pre-populated .env with
=null
for each variable.docker-entry.sh:
https://stackoverflow.com/a/77490465/17756110 If anyone is still looking for the solution to this problem.
This is an incredibly ugly hack to get this working, it converts process.env variables prefixed with VITE_ to an .env file before before runtime.
docker build file
package.json (I have to use preview instead of dev, as otherwise webworkers break on ff, ive been having fun 😕)
.patch/env_bind.js
I don’t recommend using this, but in my case I dont have another choice until import.meta.env gets all the env variables