-
-
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
Improved astro:env errors #11381
Comments
The reproduction does not show this issue, please update it |
Hello @xino1010. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
@florian-lefebvre here you'll find an example to reproduce the bug. |
I think this is because at https://github.com/withastro/astro/blob/main/packages/integrations/node/src/server.ts#L11 (and same for vercel and netlify), |
Should we? CHAT_GPT_SECRET=123456 astro preview |
Maybe we're talking about two different things:
import { defineConfig, envField } from "astro/config";
import node from "@astrojs/node";
// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({
mode: "standalone",
}),
experimental: {
env: {
schema: {
CHAT_GPT_KEY: envField.string({
context: "server",
access: "secret",
}),
},
},
},
}); ---
import { CHAT_GPT_KEY } from "astro:env/server";
console.log(CHAT_GPT_KEY);
---
so the issue here is, in preview and build mode, the secret var is not accessible. 11:18:15 [ERROR] EnvInvalidVariable: The following environment variable does not match the data type and/or properties defined in `experimental.env.schema`: CHAT_GPT_KEY is not of type string |
Yeah I agree errors need improvements, regarding what validation rule is failing exactly (eg. startsWith) |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
astro.config.mjs
.Use the env var, for example,
src/data-source.ts
.Defining the var with access
public
, there is not error:What's the expected result?
Launch the application without any error.
Link to Minimal Reproducible Example
https://github.com/xino1010/astro-env-example
Participation
The text was updated successfully, but these errors were encountered: