You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
v5: present-but-empty .env keys (KEY=) are dropped and reported as "not defined" #603
Since 4.0.0 (still in 5.0.0), a key that is present in .env with an empty value (API_KEY=) is treated as if it were missing. With safe: true and allowUndefined: false the build fails:
"API_KEY" is not defined in .env
In 3.4.11 the same file worked: the import compiled to "".
Cause
index.js (5.0.0, lines 127–129) builds the final env object with undefObjectAssign({}, fileEnv):
undefObjectAssign copies a key only when its value is truthy, so every empty-string value is dropped before the Object.hasOwn(env, importedId) check runs. dotenv.parse itself does return the key with "".
In 3.4.11 the overlays (.env.<mode>, .env.local, …) were merged into the parsed main-file object, so a key present in the main .env with an empty value stayed defined:
A key that exists in the file, even with an empty value, is defined (as the empty string). Leaving an optional secret blank in local development while CI fills it in is a common pattern, and the safe mode error message is misleading here because the key is defined.
safeObjectAssign still refuses to overwrite with a falsy host value, and dotenvTemporary is already filtered, so nothing else changes. Happy to open a PR if this is the preferred direction.
Activity
ashishgit4 commentedon Oct 10, 2026
/assign