Quick answer

Keys in .env files must follow a strict format: start with a letter (A-Z, a-z) or underscore (_), then only letters, digits, and underscores.

.env Invalid Key

Keys in .env files must follow a strict format: start with a letter (A-Z, a-z) or underscore (_), then only letters, digits, and underscores. Keys starting with a number or containing hyphens, spaces, or other characters are invalid.

Common causes

How to fix

Examples

Bad

my-key=value

Good

MY_KEY=value

FAQ

Can I use hyphens in .env keys?
Many loaders allow it, but strict validators and some runtimes expect only [A-Za-z_][A-Za-z0-9_]*. Use underscores for portability.

Fix it now

Try in validator (prefill this example)

Related

All tools · Canonical