-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
"secret server variables" are validated at build time violating the docs #12690
Comments
It is not validated at build time here. Indeed, you call a secret in a prerendered page and as you can see, the error is thrown while rendering static pages ( |
@florian-lefebvre Our build started failing once we upgraded from We have In fact, I deleted the whole export default defineConfig({
output: "server",
adapter: node({ mode: "standalone" }),
prefetch: true,
security: { checkOrigin: true },
env: {
schema: {
KEYCLOAK_CLIENT_SECRET: envField.string({
context: "server",
access: "secret",
})
}
}
}) Astro build:
|
@pothos-dev can you provide a minimal reproduction through https://astro.new/repro? |
I managed to localize the issue: Since 5.0.0, Previously, the middleware was merely compiled (?), not evaluated by A workaround might be to not access environment variables in the root scope of a module that is imported in middleware, but wrap the access in a function. But this requires us to rewrite a lot of code (our As an example, run |
@ematipico I'll need your help on this one |
This was never the case. The middleware has always been loaded during the build, if you have pre-rendered pages. This hasn't changed, AFAIK. |
Okay, but it wasn't the case if you had only server-rendered pages. Now it is the case even if you have only server-rendered pages, or no pages at all. |
@pothos-dev can you try this preview release and tell us if that fixes your issue? |
@ematipico I can confirm that this branch fixes the build-time issues we've seen! |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
Chrome
Describe the Bug
As described in the documentation, only public environment variables are validated during build time. However, when I set an environment variable as a server secret, it is still being validated at build time, resulting in an error.
While I can temporarily resolve this by assigning a default value to the variable, this workaround is not mentioned in the documentation, and it does not seem to align with the intended behavior outlined.
astro.config.mjs
Error info
What's the expected result?
The secret server variables should not be validated at build time.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-noe3rg6f?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: