The key is duplicated only within the same mapping
YAML objects are mappings. Within one mapping, each decoded key must identify one unambiguous value. A key named build can safely exist inside scripts while another build exists inside a different object. It cannot appear twice at the document root.
Ambiguous root keys
name: local-dev-kit
scripts:
build: astro build
build:config: node build.mjs
build: astro checkOne scripts mapping
name: local-dev-kit
scripts:
build: astro build
build:config: node build.mjs
check: astro checkThe corrected version indents every command under one scripts key and gives each script a distinct name.
Why strict converters stop
Some YAML implementations keep the first duplicate value; others keep the last. Either behavior can hide configuration loss. A converter that reports DUPLICATE_KEY is refusing to guess which value you intended.
The line number identifies the repeated occurrence, while the diagnostic should also identify the first definition. Review both locations before editing.
Common causes
- Lost indentation: child entries align with their parent and become root keys.
- Copied blocks: a second
scripts,dependencies, or environment section is pasted into the same mapping. - Repeated shorthand: multiple commands are all named
testorbuildinstead oftest:e2eandbuild:config. - Tabs or mixed spacing: visually similar indentation produces a different hierarchy. YAML indentation should use spaces.
Correct the source without losing work
- Do not delete every highlighted line. First identify the mapping each entry belongs to.
- Move related entries under one parent using consistent spaces.
- Rename commands that genuinely need separate values.
- Parse again and inspect the resulting hierarchy before converting formats.
- If the source came from
package.json, use the original JSON when available; YAML is only an alternate representation.
Limitations
A parser can identify structural ambiguity, but it cannot know which script name, parent section, or indentation you intended. The correction remains a developer decision. Review command behavior separately; valid YAML does not guarantee that a package script is safe or correct.