denoland/deno · error · anyhow::Error
Invalid YAML
Error message
Invalid YAML: {e} What it means
Deno reads pnpm-workspace.yaml to support pnpm-style workspaces and catalogs, parsing it with the same yaml_parser CST already used by `deno fmt` (parse_pnpm_workspace, cli/util/pnpm_workspace.rs:249-252). Any YAML syntax error — bad indentation, tabs, unclosed quotes or flow collections, duplicate keys — aborts loading with "Invalid YAML: {parser error}", including the position the parser reported.
Solutions
- Fix the reported position: the {e} in the message carries the parser's line/column detail.
- Validate the file before retrying: `pnpm install` (pnpm's own parser) or a YAML linter / yq pnpm-workspace.yaml.
- Check for tabs (YAML requires spaces), smart quotes, and duplicate top-level keys.
Example fix
# pnpm-workspace.yaml — before
packages:
- 'apps/*'
catalog:
react: ^18.2.0
lodash: ^4.17.21 # wrong indentation
# after
catalog:
react: ^18.2.0
lodash: ^4.17.21 Defensive patterns
Strategy: validation
Validate before calling
# Validate pnpm-workspace.yaml before running deno in the workspace
if command -v pnpm >/dev/null; then pnpm install --lockfile-only >/dev/null \
|| { echo 'pnpm-workspace.yaml is invalid'; exit 1; }; fi
deno task build Prevention
- Use spaces (never tabs) and consistent indentation when editing catalog/workspace YAML.
- Lint the file (yq, a YAML extension, or pnpm itself) after every hand edit.
- Beware smart quotes and copy-paste from rich-text sources.
When it happens
Trigger: Any workspace-root pnpm-workspace.yaml that fails to parse, hit as soon as Deno loads config (deno install/task/run/check) in that directory; hand-edited catalog blocks with misaligned indentation are the classic case.
Common situations: Merging catalog entries by hand; smart quotes or tabs pasted from chat/docs; renaming keys and breaking list syntax; YAML files edited by tools that emit single quotes oddly.
Related errors
- A deno.json file could not be found or created
- Bench attempted to exit with exit code
- workspace root is not a local directory
- Both 'cert' and 'key' must be provided to enable HTTPS
- Cannot generate declarations for files with different…
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/fd201cb16e3e77e8.
Report an issue: GitHub.
Appendix: source
Thrown at cli/util/pnpm_workspace.rs:252
}
fn string_map_to_value(map: &IndexMap<String, String>) -> CstInputValue {
CstInputValue::Object(
map
.iter()
.map(|(k, v)| (k.clone(), CstInputValue::String(v.clone())))
.collect(),
)
}
// ===========================================================================
// pnpm-workspace.yaml parsing (via the yaml_parser CST already used by
// `deno fmt`, so no new YAML dependency is introduced).
// ===========================================================================
fn parse_pnpm_workspace(text: &str) -> Result<PnpmWorkspace, AnyError> {
let tree = yaml_parser::parse(text)
.map_err(|e| deno_core::anyhow::anyhow!("Invalid YAML: {e}"))?;
let Some(root) = Root::cast(tree) else {
return Ok(PnpmWorkspace::default());
};
let Some(block_map) = root
.documents()
.next()
.and_then(|doc: Document| doc.block())
.and_then(|block| block.block_map())
else {
return Ok(PnpmWorkspace::default());
};
let mut result = PnpmWorkspace::default();
for entry in block_map.entries() {
let Some(key) = entry.key().map(|k| k.syntax().clone()) else {
continue;
};
let Some(key_name) = scalar_text(&key) else {View on GitHub (pinned to 9ad36f7a2c)