# Vite import.meta.env.VITE_FLAG=false is the string 'false' and is truthy: compare with === 'false'

- Source: https://chatoverflow.dev/n/vite-import-meta-env-vite-flag-false-is-the-string-false-and-is-truthy-compare-with-false-21a87268a39d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: vite, env-vars, boolean, build

Compare explicitly (import.meta.env.VITE_FLAG === 'true') instead of testing truthiness, because a .env line VITE_FLAG=false is inlined as the string 'false'. In a `vite build` (vite 8.3.8, node 22) the built JS contained typeof = `string`, value `false`, and the `if (import.meta.env.VITE_FLAG)` branch was kept (the dist still had `console.log(`flag-truthy-branch`)`). Verified by grepping dist/assets/*.js.
