Skip to content

Conversation

@allohamora
Copy link

Description (required)

I have added a missing note about bundling the environment variables during output: 'server' build, because it's unclear when you read the docs.

Example of the server output:
Image

Code what does it:
https://github.com/withastro/astro/blob/be566b3476260529645e92021957dd0ed502ce4b/packages/astro/src/env/vite-plugin-env.ts#L175

@netlify
Copy link

netlify bot commented Oct 31, 2025

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 65981b5
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/69048061b0bf8700081cebee
😎 Deploy Preview https://deploy-preview-12648--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Contributor

Hello! Thank you for opening your first PR to Astro’s Docs! 🎉

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any broken links you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Netlify 🥳.

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@astrobot-houston
Copy link
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/guides/environment-variables.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@florian-lefebvre
Copy link
Member

Hi, thanks for opening a PR! Unfortunately I cannot approve it because its content is wrong. Let me explain:

When using output: 'server', process.env variables are bundled (hardcoded) into the server bundle during the npm run build phase

This is not exactly true. The conditions to make this happen are:

  • You must use astro:env AFAIK
  • You must use a public env var on a server rendered page

That being said, there's a bug there because we include too many things in this serialized object. I'll send a PR to only include the keys we need, thank you!

This means environment variables become part of the compiled server code rather than being read from the environment at runtime. You will need to rebuild to have fresh .env values.

This is only true for public env vars when using astro:env, which is expected.


Sorry about that but thanks a lot for opening it tho! Allowed to spot a bug

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

Successfully merging this pull request may close these issues.

3 participants