A Vite plugin (v1.0.2) for build-time validation and injection of environment variables using schema libraries like Zod, Valibot, ArkType, and Effect Schema via the Standard Schema V1 spec. It validates .env values against a defined schema early in the Vite config resolution (or on module load) and exposes them through a virtual module `virtual:env`. Key differentiators from other env plugins (e.g., @julr/vite-plugin-validate-env) include full compatibility with any Standard Schema library and zero runtime dependencies beyond the schema library. Released in July 2025 with an active maintenance cadence.
npm install vite-plugin-env-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic validation with Zod: creates env schema, injects validated vars, demonstrates TypeScript declaration for type-safe access.
If you relied on 'load' behavior, set validateOn: 'load' explicitly in plugin options.
Use conditional requires or mock the module in test environments (e.g., vitest config with resolve.alias).
Use z.coerce for number/boolean defaults, or validate transformed values after string parsing.
Update to latest version; custom validation should implement Standard Schema V1.
Create an env.d.ts file in your project root declaring module 'virtual:env' with the correct type inference.
Ensure the variable is present in your .env file and, if using Vite's default env prefix, it starts with VITE_.
Use z.coerce.boolean() for env vars that are strings 'true'/'false' or ensure the default matches the string representation.