no-restricted-import-meta-env
Disallow client-side import.meta.env keys that are not Vite built-ins and do not match an allowed public prefix.
Rule catalog ID: R007
Targeted pattern scopeโ
- browser-bound source files
- code that reads public env values from
import.meta.env
What this rule reportsโ
This rule reports import.meta.env property reads whose keys are:
- not built-in Vite keys such as
MODEorDEV - not prefixed by an allowed public prefix such as
VITE_
Why this rule existsโ
Client bundles should read only values that you intentionally expose.
This rule helps reviewers spot accidental reads from server-only or internal env names.
โ Incorrectโ
const secret = import.meta.env.SECRET_TOKEN;
โ Correctโ
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL;
const mode = import.meta.env.MODE;
Behavior and migration notesโ
- built-in keys such as
MODE,DEV,PROD,SSR, andBASE_URLare allowed - the default allowed public prefix is
VITE_ - configure additional prefixes if your repository uses another explicit public prefix
ESLint flat config exampleโ
import vite from "@typpi/eslint-plugin-vite";
export default [
vite.configs.client,
{
rules: {
"vite/no-restricted-import-meta-env": [
"error",
{
allowPrefixes: ["VITE_", "PUBLIC_"],
},
],
},
},
];
When not to use itโ
Disable this rule if your repository does not read env values from browser code or if another policy layer already enforces public env naming.