The workshop’s key board: which .env keys go out to the browser, and in what form? Try a secret given a VITE_ name too; this page’s own import.meta.env is…
Why it matters
One prefix decides what becomes public. A missing prefix makes a value undefined; a misplaced one sends a secret API key to anyone who opens DevTools. And since values are written at build time, changing .env afterwards does not change the site.
The key idea
import.meta.env.VITE_X is not a variable: it is replaced by text at build
Common mistakes
An API key in a VITE_ variable, then visible in DevTools Everything starting with VITE_ is written into the JS file sent to the browser. Keep secrets on the server under names without VITE_, and let the server call the secret API.
The secret is gone from .env, but the worry stays Published bundles hold the text from their old build, and copies may sit in caches or in someone’s hands. Rotate the key at the API provider; removing it from .env does not take it back.
import.meta.env.API_URL is undefined although .env sets it Without the VITE_ prefix (or the envPrefix you set), Vite does not hand that variable to browser code. Rename it VITE_API_URL, then restart the dev server or build again.
Try it in this playground
See undefined from a key with no prefixAPI_URL never reaches browser code.
See the secret go into the bundle The name VITE_API_SECRET is enough to make it public.
Change .env without building again The bundle keeps the old address.
Print the whole import.meta.env Every VITE_ key goes along, unused ones too.