Skip to main content

no-empty-env-prefix

Disallow empty envPrefix values that would expose every environment variable to import.meta.env.

Rule catalog ID: R004

Targeted pattern scopeโ€‹

  • vite.config.*
  • vitest.config.* when Vite config options are reused there

What this rule reportsโ€‹

This rule reports envPrefix values like:

  • ""
  • ["VITE_", ""]

Why this rule existsโ€‹

envPrefix is a boundary between public browser values and private process environment values.

An empty prefix removes that boundary.

โŒ Incorrectโ€‹

import { defineConfig } from "vite";

export default defineConfig({
envPrefix: "",
});

โœ… Correctโ€‹

import { defineConfig } from "vite";

export default defineConfig({
envPrefix: "VITE_",
});
import { defineConfig } from "vite";

export default defineConfig({
envPrefix: ["VITE_", "PUBLIC_"],
});

Behavior and migration notesโ€‹

  • choose explicit public prefixes instead of trying to expose everything
  • if you need server-only access, keep that logic outside browser bundles

ESLint flat config exampleโ€‹

import vite from "@typpi/eslint-plugin-vite";

export default [vite.configs.configs];

When not to use itโ€‹

Disable this rule only if your repository intentionally exposes every environment variable to browser code.

Package documentationโ€‹

Further readingโ€‹