What exactly is this update with version 5.13 of astro?
https://docs.astro.build/en/reference/experimental-flags/static-import-meta-env/
4 messages · Page 1 of 1 (latest)
What exactly is this update with version 5.13 of astro?
https://docs.astro.build/en/reference/experimental-flags/static-import-meta-env/
Hi @timid elk. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
With Astro version 5.13, a new experimental flag called staticImportMetaEnv was introduced. This flag changes how Astro handles environment variables accessed via import.meta.env to align with Vite’s behavior.
Key changes with this update:
import.meta.env into booleans or numbers (e.g., "true" to true, "1" to 1). With this flag enabled, values are no longer coerced; they remain as strings, just like in Vite.process.env fallback: Astro used to replace some import.meta.env variables with references to process.env (especially for non-public variables). With the flag enabled, this replacement no longer happens—import.meta.env values are always inlined.process.env fallback, you may need to update your code. For example, you might need to manually convert string values to booleans or numbers, or switch to using process.env directly for certain variables.How to enable:
// astro.config.mjs
import { defineConfig } from "astro/config"
export default defineConfig({
experimental: {
staticImportMetaEnv: true,
}
})
Example update:
If you previously relied on coercion:
const enabled = import.meta.env.ENABLED === "true";
If you previously relied on process.env:
const password = process.env.DB_PASSWORD;