Experimental raw environment variables values
यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।
Type: boolean
Default: false
astro@5.12.0
नया
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:
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.
Updating your project
Section titled “Updating your project”If you were relying on this coercion, you may need to update your project code to apply it manually:
const enabled: boolean = import.meta.env.ENABLEDconst enabled: boolean = import.meta.env.ENABLED === "true"
If you need coercion in Astro, we recommend you use astro:env
.