Quick answer
In a mapping, each key should appear only once at the same level.
YAML Duplicate Key
In a mapping, each key should appear only once at the same level. If the same key is repeated, parsers may error or use only the last value.
Common causes
- Copy-pasting blocks and leaving the same key name in multiple places.
- Merging configs that both define the same key.
- Typo intended to be a different key (e.g. env vs envs).
How to fix
- Remove or rename duplicate keys so each key is unique at its level.
- If merging is desired, use a single key and combine values (e.g. arrays) under it.
- Validate with a YAML validator to see which line has the duplicate.
Examples
Bad
name: app name: other
Good
name: app version: other
FAQ
- Can YAML have two keys with the same name?
- No. At the same level, each key must be unique; the second occurrence overwrites or causes an error depending on the parser.
- How do I have multiple values for one key in YAML?
- Use a list as the value: key: [a, b, c] or key: with a newline and list items (e.g. - a, - b).
Fix it now
Try in validator (prefill this example)