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

Docs doesn't specify that import.meta.env is evaluated at build time with SSR adapter. #8509

Closed
feelixe opened this issue Jun 13, 2024 · 2 comments · Fixed by #8533
Closed
Labels
good first issue Good for newcomers help wanted Issues looking for someone to run with them! improve documentation Enhance existing documentation (e.g. add an example, improve description)

Comments

@feelixe
Copy link
Contributor

feelixe commented Jun 13, 2024

📋 Explain your issue

In the docs it's not mentioned that using import.meta.env will be evaluated at build time. If you are using static generation, that goes without saying. But with a SSR adapter, I think many will expect this to be evaluated per request at runtime. I at least did until i looked in the transpiled server files.

I believe some clarification would be good.

@Fryuni
Copy link
Member

Fryuni commented Jun 14, 2024

It might improve discoverability, but the information is available from that page.

The first line states that Astro uses Vite's built-in handling for environment variables and links to their docs. The linked page starts with:

Vite exposes env variables on the special import.meta.env object, which are statically replaced at build time.

The same could be said for any other Vite details about env vars, like .env.[mode].local files also being loaded to allow for untracked .env files.

@sarah11918
Copy link
Member

@feelixe Would it solve your problem if we updated our sentence there to include the content on the linked page to Vite, maybe like:

Astro uses Vite’s built-in support for environment variables, which are statically replaced at build time, and lets you use any of its methods to work with them.

If so we would happily accept a PR to docs with that update!

@sarah11918 sarah11918 added improve documentation Enhance existing documentation (e.g. add an example, improve description) good first issue Good for newcomers help wanted Issues looking for someone to run with them! labels Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Issues looking for someone to run with them! improve documentation Enhance existing documentation (e.g. add an example, improve description)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants