Common causes
1. A missing closing quote
The most common case: the value was edited and its closing quote deleted. Everything up to the next quote, often several lines later, becomes part of the value.
APP_NAME="Invoice Service
DEBUG=falseAPP_NAME="Invoice Service"
DEBUG=false2. An apostrophe inside a single-quoted value
Single quotes cannot be escaped inside single-quoted values, so 'Don't stop' ends after Don. Use double quotes around text that contains apostrophes.
TAGLINE='Don't stop'TAGLINE="Don't stop"3. Unescaped double quotes inside a double-quoted value
An inner " closes the value early. Escape it with a backslash, or switch to single quotes if the value has no apostrophes.
GREETING="Say "hi" to Ada"GREETING="Say \"hi\" to Ada"4. A multi-line secret pasted without care
PEM keys and certificates span many lines. Keep them in double quotes with the closing quote after the END line, or put the whole key on one line with \n escapes, which every dotenv implementation understands.
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBg
-----END PRIVATE KEY-----PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBg\n-----END PRIVATE KEY-----"Frequently asked questions
Why are my variables undefined even though they are in the file?
An unterminated quote above them turned those lines into part of an earlier value. Check the line where the first missing variable appears and the quotes on the lines before it.
Do .env values need quotes at all?
Only when the value has leading or trailing spaces, a # that is not a comment, or line breaks. Plain values such as URLs and numbers can be written without quotes.
Is there one standard .env syntax?
No. dotenv for Node, python-dotenv, Docker Compose and shell sourcing differ in how they handle quotes, escapes and multi-line values. Simple KEY=value lines with double quotes when needed work everywhere.