.env file not loading: values with spaces, inline comments and duplicate keys

Last reviewed 2026-09-19

.env files look simple, but parsers disagree on the details. Spaces around the equals sign, unquoted values that contain spaces or # characters, and keys that appear twice cause values to be cut off, ignored or overridden.

Messages you might see

  • “Failed to parse .env / dotenv parse error”
  • “A variable has the wrong value, or is undefined”
  • “Invalid variable name”

Why it happens

  • Spaces around =, or a value with spaces that is not quoted.
  • An inline # comment read as part of the value or as the end of it.
  • A key that appears twice, with the last (or first) copy winning.
  • A line that is not KEY=VALUE, or a key with invalid characters.

Try this first (free, no tool needed)

  1. Quote any value that contains spaces, #, $ or quotes.
  2. Use KEY=value with no spaces around the equals sign.
  3. Search the file for keys that appear twice.
  4. Check the library's docs, since expansion of $VARIABLES differs between parsers.

If that didn't work

These tools run in your browser. Your file is read and repaired on your own device and is never uploaded.

.env File Repair

Tidies spaces around equals signs, quotes values that contain spaces or special characters, removes inline comments from unquoted values, fixes invalid key names, comments out lines that aren't KEY=VALUE and resolves duplicate keys the way you choose. Never commit real secrets while testing, and remember the file stays on your device.

Open .env File Repair

Common questions

Are my secrets safe in a .env file I load here?

The file is processed in your browser and not uploaded. Even so, treat any file with real secrets carefully and rotate keys that were exposed elsewhere.

Is my file uploaded anywhere?

No. The tool runs as a program inside your own browser, so the file is read and repaired on your device and never sent to a server.

Related guides