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

Missing .env variables are incorrectly resolved in SSR mode #11465

Closed
1 task
Lesmian opened this issue Jul 14, 2024 · 2 comments
Closed
1 task

Missing .env variables are incorrectly resolved in SSR mode #11465

Lesmian opened this issue Jul 14, 2024 · 2 comments
Labels
needs triage Issue needs to be triaged

Comments

@Lesmian
Copy link

Lesmian commented Jul 14, 2024

Astro Info

Astro                    v4.11.5
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   server
Adapter                  @astrojs/node
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

In SSR mode not found env variables are replaced during build with object containing all public variables (including build-in ones like DEV/PROD/BASE_URL) instead of just being undefined.

Example:
Import variable which is not defined in .env file:
const notFound = import.meta.env.PUBLIC_NOT_FOUND;

Build project in server mode with: npm run build

In the dist folder you will see this as variable value:
const notFound = {"PUBLIC_FOUND": "This variable was found", "BASE_URL": "/", "MODE": "production", "DEV": false, "PROD": true, "SSR": true, "SITE": undefined, "ASSETS_PREFIX": undefined}.PUBLIC_NOT_FOUND;

What's the expected result?

Not defined variables should be replaced during build with undefined value. It works like that in static rendering mode as well as when using the new experimental.env. In the case of experimental.env it works correctly (so the value is undefined) in SSR mode as well, so the problem appears only in SSR mode using import.meta.env feature.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-8xejlh?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jul 14, 2024
@bluwy
Copy link
Member

bluwy commented Jul 15, 2024

Is this a Vite issue? I believe PUBLIC_ env vars are handled by Vite only.

@bluwy
Copy link
Member

bluwy commented Jul 23, 2024

Closing in favour of vitejs/vite#17710

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants