{"record":{"id":"c9a027fc20cb7889","repo":"denoland/deno","slug":"existing-is-not-valid-json-jsonc-e-fix-or-r","errorCode":null,"errorMessage":"existing {} is not valid JSON/JSONC: {e}. Fix or remove it and re-run `deno sync-types`.","messagePattern":"existing (.+?) is not valid JSON/JSONC: (.+?)\\. Fix or remove it and re-run `deno sync-types`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tsc/tsconfig_gen.rs","lineNumber":322,"sourceCode":"      .expect(\"failed to serialize tsconfig\");\n    return std::fs::write(&root_tsconfig_path, &content);\n  }\n\n  // Parse as JSONC and edit the raw text by byte range (rather than\n  // re-serializing) so the user's comments and formatting are preserved. An\n  // unparseable file is a hard error rather than being silently overwritten.\n  use jsonc_parser::ast::ObjectPropName;\n  use jsonc_parser::ast::Value as JsoncValue;\n  let ast = jsonc_parser::parse_to_ast(\n    &content,\n    &jsonc_parser::CollectOptions {\n      comments: jsonc_parser::CommentCollectionStrategy::Off,\n      tokens: false,\n    },\n    &jsonc_parser::ParseOptions::default(),\n  )\n  .map_err(|e| {\n    std::io::Error::new(\n      std::io::ErrorKind::InvalidData,\n      format!(\n        \"existing {} is not valid JSON/JSONC: {e}. Fix or remove it and re-run \\\n         `deno sync-types`.\",\n        root_tsconfig_path.display()\n      ),\n    )\n  })?;\n\n  let Some(JsoncValue::Object(obj)) = ast.value else {\n    // Not a JSON object (empty file, array, ...) — leave it alone.\n    return Ok(());\n  };\n  let extends = obj.properties.iter().find(|p| {\n    let name = match &p.name {\n      ObjectPropName::String(s) => s.value.as_ref(),\n      ObjectPropName::Word(w) => w.value,\n    };","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tsc/tsconfig_gen.rs#L304-L340","documentation":"The ensure-root step of tsconfig generation refuses to touch an existing root tsconfig.json it cannot parse: `jsonc_parser::parse_to_ast` fails on the file's contents (comments and trailing commas allowed, so failures are real syntax errors). Because silently overwriting user content would destroy data, an unparseable file is a hard `InvalidData` error and the message instructs you to fix or remove it and re-run `deno sync-types`.","triggerScenarios":"Running `deno sync-types` when a root tsconfig.json already exists but contains unparseable content — typically unresolved git merge-conflict markers, encoding corruption, or a truncated write.","commonSituations":"Repos mid-rebase with conflict markers left in tsconfig.json; files damaged by a crash or partial save; committed files with non-UTF-8 bytes from a bad merge.","solutions":["Inspect tsconfig.json for conflict markers (`<<<<<<<`/`=======`/`>>>>>>>`) or truncation and repair the syntax, then re-run `deno sync-types`.","If the file is not precious, back it up or remove it and re-run — the command regenerates a valid one.","Run `git diff --check` / a JSONC lint before syncing to catch damaged files early."],"exampleFix":"# before\n$ deno sync-types\n# → existing /repo/tsconfig.json is not valid JSON/JSONC: ...\n\n# after (repair, or regenerate)\n$ git checkout -- tsconfig.json && deno sync-types\n$ rm tsconfig.json && deno sync-types","handlingStrategy":"validation","validationCode":"# ensure the root tsconfig parses before deno sync-types\ndeno eval 'import { parse } from \"jsr:@std/jsonc\"; parse(Deno.readTextSync(\"tsconfig.json\"));'","typeGuard":null,"tryCatchPattern":"try {\n  await runDeno(\"sync-types\");\n} catch (err) {\n  if (String(err).includes(\"not valid JSON/JSONC\")) {\n    // fix the file, or rename it away and re-run to regenerate\n  } else throw err;\n}","preventionTips":["Run git diff --check for conflict markers before syncing","Commit only parseable tsconfig — add a CI parse step","Back up custom tsconfig content before letting tooling rewrite it"],"tags":["tsconfig","jsonc","deno-sync-types","parse-error","merge-conflict"],"backgroundTag":"invalid-json-config","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}