Fix .env file syntax

.env files use KEY=VALUE format. Invalid syntax—spaces around =, unquoted values with special chars, or wrong line endings—can cause parse errors.

Dotenv parsers are not JSON. Spaces around `=`, unquoted values with `#`, and multiline values all have specific rules per library.

Common causes

  • Spaces around `=` when the parser does not trim keys (`KEY = value`).
  • Unquoted values containing `#` (interpreted as comment start).
  • Unescaped newlines inside unquoted values.

How to fix

  • Use `KEY=value` without spaces, or quote the value: `KEY="value with spaces"`.
  • Quote values that include `#`, `=`, or spaces.
  • Validate with the Env file validator tool for this project’s parser expectations.

Use our tool

Validate .env

Advertisement

All guides