Closed xino1010 closed 2 months ago
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 needs repro
will be closed if they have no activity within 3 days.
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), process.env
is not loaded with .env
. Maybe we should call loadEnv
? @ematipico
I think this is because at
main
/packages/integrations/node/src/server.ts#L11 (and same for vercel and netlify),process.env
is not loaded with.env
. Maybe we should callloadEnv
? @ematipico
Should we? astro preview
is meant to run a production-like server, and I doubt users will use .env
to load their secrets in production. Those secrets should injected via process.env
. In this particular case, the secret should be passed like this
CHAT_GPT_SECRET=123456 astro preview
I think this is because at
main
/packages/integrations/node/src/server.ts#L11 (and same for vercel and netlify),process.env
is not loaded with.env
. Maybe we should callloadEnv
? @ematipicoShould we?
astro preview
is meant to run a production-like server, and I doubt users will use.env
to load their secrets in production. Those secrets should injected viaprocess.env
. In this particular case, the secret should be passed like thisCHAT_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", }), }, }, }, });
```typescript
---
import { CHAT_GPT_KEY } from "astro:env/server";
console.log(CHAT_GPT_KEY);
---
getSecret
function can be used to get the value of an env var not defined in astro.config.mjs
.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