ArkEnv

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")

Validator Mode

By default, ArkEnv uses ArkType for validation. However, you can use any Standard Schema compatible library (like Zod or Valibot) by setting the validator option to "standard".

In this mode, you don't need to install arktype.

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),
    }, {
      validator: "standard"
    }),
  ],
});

Important

By default, this plugin uses ArkType for validation.

You can also use validator: "standard" if you prefer using Zod or Valibot directly without an ArkType dependency.

See Validator mode 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 the default validator mode, you should 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.