Introduction

What is this?

The ArkEnv plugin for Vite lets you validate environment variables at build-time with ArkEnv.

vite.config.ts
import  from "@arkenv/vite-plugin";
import {  } from "vite";

export default ({
  : [
    ({
      : "number.port",
      : "string",
    }),
  ],
});

With this setup, if any environment variable is missing or invalid, your dev server won't start and your production build will fail with an error:

Terminal
ArkEnvError: Errors found while validating environment variables
  VITE_MY_VAR must be a string (was missing)
  PORT must be an integer between 0 and 65535 (was "hello")

Using Standard Schema validators (Zod, Valibot)

This plugin uses ArkType for validation, which natively supports Standard Schema. You can freely mix ArkType DSL strings with Zod or Valibot validators in the same schema - no extra configuration needed.

vite.config.ts
import { defineConfig } from "vite";
import arkenv from "@arkenv/vite-plugin";
import { z } from "zod";

export default defineConfig({
  plugins: [
    arkenv({
      VITE_API_URL: z.url(),
      VITE_API_KEY: z.string().min(1),
      VITE_DEBUG: "boolean",
    }),
  ],
});

Important

This plugin requires ArkType to be installed.

For a zero-ArkType setup, use arkenv/standard directly in your app code instead.

See Standard Schema validators for details.

Installation

npm install @arkenv/vite-plugin
pnpm add @arkenv/vite-plugin
yarn add @arkenv/vite-plugin
bun add @arkenv/vite-plugin

If you intend to use arkenv (requires ArkType), also install arktype:

npm install arktype
pnpm add arktype
yarn add arktype
bun add arktype

For some workflows (including using ArkEnv in Vite config and typing import.meta.env), a dedicated arkenv installation is needed. See ArkEnv quickstart for more instructions.