Zum Inhalt springen

Experimental raw environment variables values

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Type: boolean
Default: false

Hinzugefügt in: astro@5.12.0 Neu

Astro allows you to configure a type-safe schema for your environment variables, and converts variables imported via astro:env into the expected type.

However, Astro also converts your environment variables used through import.meta.env in some cases, and this can prevent access to some values such as the strings "true" (which is converted to a boolean value), and "1" (which is converted to a number).

The experimental.rawEnvValues flag disables coercion of import.meta.env values that are populated from process.env, allowing you to use the raw value.

To disable Astro’s coercion on values used through import.meta.env, set the experimental.rawEnvValues flag to true in your Astro configuration:

astro.config.mjs
import { defineConfig } from "astro/config"
export default defineConfig({
experimental: {
rawEnvValues: true,
}
})

Enabling this experimental flag will no longer convert string values into booleans or numbers. This aligns import.meta.env’s behavior in Astro with Vite.

In a future major version, Astro will switch to not coercing import.meta.env values by default, but you can opt in to the future behavior early using the experimental.rawEnvValues flag and if necessary, updating your project accordingly.

If you were relying on this coercion, you may need to update your project code to apply it manually:

src/components/MyComponent.astro
const enabled: boolean = import.meta.env.ENABLED
const enabled: boolean = import.meta.env.ENABLED === "true"

If you need coercion in Astro, we recommend you use astro:env.

Wirke mit Community Sponsor