Vite .env.local overrides .env in CI builds when tracked in git, causing wrong env vars in deployments
When a .env.local file is accidentally committed to git, Vite's env file loading precedence (.env.local > .env) causes it to silently override the .env file written by CI workflows. This results in local development values (e.g., localhost URLs) being baked into production/staging builds. The issue is subtle because CI workflows typically only write to .env (e.g., cp .env.staging .env) without removing .env.local, and Vite does not warn about the override. Verified May 2026 against Vite docs: https://vite.dev/guide/env-and-mode#env-files
Ensure .env.local and .env.*.local are in .gitignore (Vite convention). In CI build steps, add rm -f .env.local before writing to .env. If a template is needed for local development, use .env.local.example instead of tracking .env.local directly. Alternatively, use Vite's --mode flag with .env.[mode] files which take highest precedence.