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

SSR Pages claim for env vars they don't need (don't know how to tell it right) #13039

Open
1 task
Fenykepy opened this issue Jan 22, 2025 · 1 comment
Open
1 task
Labels
needs response Issue needs response from OP

Comments

@Fenykepy
Copy link

Fenykepy commented Jan 22, 2025

Astro Info

Astro                    v5.1.8
Node                     v20.12.1
System                   macOS (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/node
Integrations             none

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

Not browser related.

Describe the Bug

Just built my first site with Astro (migration from Gatsby).
It was a real pleasure to work with it, easy to learn, works great, big thanks to the whole team for this awesome work!

If found some strange behavior with env vars defined in astro.config.mjs env schema.
With static pages and some access: "secret" env vars, everything behaves correctly on dev, preview and production modes.
With SSR pages and some access: "secret" env vars, everything behaves correctly on dev mode, however on preview and production modes, runtime generation fails, claiming for those secret env vars while none of my SSR pages or components use them in the code.

What's the expected result?

  • SSR pages shouldn't claim for env vars they don't use, even if they are in schema.
  • SSR pages shouldn't work ind dev mode and fail in preview mode when using same env vars (it should not fail at all, or at least fail in both modes).

Link to Minimal Reproducible Example

Everything is well described in my example's README.md:
https://github.com/Fenykepy/astro-env-vars-example/

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 Jan 22, 2025
@ascorbic
Copy link
Contributor

I may be misunderstanding what you're expecting, but in the example you share, the problem is that the static page is importing the secret var, which is why it complains about it being missing. If you remove that then it builds fine without it.

If you mark an env var as secret and only use it in SSR, then it won't complain about it being unset at build because it's expecting it to be set at runtime. If you mark it as public then it will complain, because it wants to inline it.

If you want it to not complain about missing env vars then you need to set them as optional. You can then check it yourself.

Let me know if it's behaving differently.

@ascorbic ascorbic added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Issue needs response from OP
Projects
None yet
Development

No branches or pull requests

2 participants