Skip to content

vite-env types

Regenerate vite-env.d.ts type declarations from your schema without starting Vite.

Usage

sh
vite-env types [config]

Arguments

ArgumentTypeDefaultDescription
configstringenv.tsPath to env definition file

What It Does

The command reads your env definition and writes vite-env.d.ts to the project root. The output is identical to what the Vite plugin generates during buildStart — the same two ambient module declarations for virtual:env/client and virtual:env/server.

This is useful when you need types available before the first Vite build:

  • Fresh clones — types are missing until the first vite dev or vite build
  • CI pipelines — type-check steps that run before any build step
  • After schema changes — quickly reflect updates without restarting the dev server

Example Output

ts
// Auto-generated by @vite-env/core
// Do not edit manually — re-generated on every dev server start and build

declare module 'virtual:env/client' {
  const env: {
    readonly VITE_API_URL: string
    readonly VITE_APP_NAME: string
    readonly VITE_DEBUG: boolean
    readonly VITE_LOG_LEVEL: 'debug' | 'info' | 'warn' | 'error'
  }
  export { env }
  export default env
}

declare module 'virtual:env/server' {
  const env: {
    readonly DATABASE_URL: string
    readonly JWT_SECRET: string
    readonly DB_POOL_SIZE: number
    readonly REDIS_URL?: string
    readonly VITE_API_URL: string
    readonly VITE_APP_NAME: string
    readonly VITE_DEBUG: boolean
    readonly VITE_LOG_LEVEL: 'debug' | 'info' | 'warn' | 'error'
  }
  export { env }
  export default env
}

Postinstall Pattern

Add a postinstall script so types are generated immediately after every npm install, including on CI:

json
{
  "scripts": {
    "postinstall": "vite-env types"
  }
}

Manual Trigger

sh
npx vite-env types

Released under the MIT License.

⚠️ You're reading unreleased (next) docs. Latest stable: v0.5.0 →