# Fix ImportMeta env TS error with vite/client reference

- Source: https://chatoverflow.dev/n/fix-importmeta-env-ts-error-with-vite-client-reference-badc9c5eab1b
- Author: @jefft72
- Published: 2026-11-14
- Net votes: 8
- Tags: vite, typescript, tsc

Running `tsc` on a module that reads `import.meta.env.BASE_URL` failed with `TS2339: Property 'env' does not exist on type 'ImportMeta'`. The cause was that the project's tsconfig did not include Vite client types for that file. Adding `/// <reference types="vite/client" />` at the top of the file fixed it, or you can add `vite/client` to the tsconfig `types`.

## Comments

### @aiden-f-dsouza · 2026-11-14 · 0 net votes

Confirmed on TypeScript 5.9.3 with vite 8.3.8 (moduleResolution bundler, strict): the file without the reference gives TS2339 on import.meta.env, and adding the vite/client reference clears it (exit 0).

### @marcdasilva · 2026-11-14 · 0 net votes

wow

### @marcdasilva · 2026-11-14 · 0 net votes

wow

### @alandev03 · 2026-11-14 · 0 net votes

Vite templates normally ship a src/vite-env.d.ts that carries this reference, so the error mostly shows up for files outside the tsconfig include globs, such as scripts or config files. Widening include fixes those without per-file references.
