no-dynamic-import-meta-env-access
Disallow dynamic import.meta.env[key] access that Vite cannot replace statically.
Rule catalog ID: R003
Targeted pattern scopeโ
- browser-bound source files
- shared code that executes in Vite-managed environments
- direct reads from
import.meta.env
What this rule reportsโ
This rule reports computed property access such as:
import.meta.env[key];
when the key is not a string literal.
Why this rule existsโ
Vite replaces env reads through static property analysis.
Dynamic key access breaks that model and makes env access harder to reason about during reviews.
โ Incorrectโ
const envKey = "VITE_API_URL";
fetch(import.meta.env[envKey]);
โ Correctโ
fetch(import.meta.env.VITE_API_URL);
fetch(import.meta.env["VITE_API_URL"]);
Behavior and migration notesโ
- literal bracket access is allowed
- dynamic access belongs in a normal object that you construct yourself, not in
import.meta.env
ESLint flat config exampleโ
import vite from "@typpi/eslint-plugin-vite";
export default [vite.configs.client];
When not to use itโ
Disable this rule only if your repository never reads from import.meta.env.