Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte-kit preview doesn't pick up env vars declared in .env #3040

Closed
Rich-Harris opened this issue Dec 13, 2021 · 3 comments
Closed

svelte-kit preview doesn't pick up env vars declared in .env #3040

Rich-Harris opened this issue Dec 13, 2021 · 3 comments

Comments

@Rich-Harris
Copy link
Member

Describe the problem

During development, Vite loads .env files according to this logic. svelte-kit preview doesn't read .env files; as such, env vars are missing.

Describe the proposed solution

Load .env files with the same logic Vite uses (this is handwavy — Vite allows arbitrary 'modes', so it's unclear which file(s) we'd load in preview beyond .env and .env.local. .env.prod and .env.prod.local?)

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

@Conduitry
Copy link
Member

Hmm I have mixed feelings about whether this would be the desired behavior. Production builds don't automatically look at .env (I admit I haven't specifically checked, but I hope they do not!) so why should previews?

preview loading .env might be convenient, but it sounds unwise to me. As in production, you should be responsible for making sure the environment variables in question are actually present in your environment.

@matmoxam
Copy link

I think this is in relation to using tools like dotenv and env-cmd. The intended purpose is to load env variables at runtime. Is there a better way to load env variables at runtime?

@Rich-Harris
Copy link
Member Author

closing in favour of #4296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants