{"record":{"id":"77c4a2cdf142bae7","repo":"withastro/astro","slug":"unknown-error-parsing-tsconfig-json-or-jsconfig-js","errorCode":null,"errorMessage":"Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.","messagePattern":"Unknown error parsing tsconfig\\.json or jsconfig\\.json\\. Could not update TypeScript settings\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/cli/add/index.ts","lineNumber":465,"sourceCode":"\t}\n\n\tconst updateTSConfigResult = await updateTSConfig(cwd, logger, integrations, flags, {\n\t\taddIncludes: hasCloudflareIntegration ? ['./worker-configuration.d.ts'] : [],\n\t});\n\n\tswitch (updateTSConfigResult) {\n\t\tcase 'none': {\n\t\t\tbreak;\n\t\t}\n\t\tcase 'cancelled': {\n\t\t\tlogger.info(\n\t\t\t\t'SKIP_FORMAT',\n\t\t\t\tmsg.cancelled(`Your TypeScript configuration has ${bold('NOT')} been updated.`),\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t\tcase 'failure': {\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.`,\n\t\t\t);\n\t\t}\n\t\tcase 'updated':\n\t\t\tlogger.info('SKIP_FORMAT', msg.success(`Successfully updated tsconfig`));\n\t}\n}\n\nfunction isAdapter(\n\tintegration: IntegrationInfo,\n): integration is IntegrationInfo & { type: 'adapter' } {\n\treturn integration.type === 'adapter';\n}\n\n// Convert an arbitrary NPM package name into a JS identifier\n// Some examples:\n//  - @astrojs/image => image\n//  - @astrojs/markdown-component => markdownComponent","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/cli/add/index.ts#L447-L483","documentation":"`astro add` runs updateTSConfig() to patch tsconfig/jsconfig for the newly added integration. If that routine returns 'failure' (the existing tsconfig.json or jsconfig.json could not be parsed as JSON, or could not be updated), `astro add` aborts by throwing this generic Error. The message is intentionally vague because the underlying parser already logged specifics.","triggerScenarios":"Running `astro add <integration>` when the project's tsconfig.json or jsconfig.json contains JSON syntax errors (trailing commas, unquoted keys, comments in a non-JSONC parse path, BOM/encoding issues), so updateTSConfig cannot read or rewrite it.","commonSituations":"Hand-edited tsconfig with a trailing comma or single-quoted string; tsconfig with `//` comments when the parser is not in JSONC mode; a corrupted/half-written tsconfig from a botched merge; a jsconfig with the same problems; an editor that auto-inserted a bad comma.","solutions":["Open tsconfig.json/jsconfig.json and run it through a JSON validator (or `npx tsc --noEmit` which will surface parse errors).","Remove trailing commas, quote all keys, and ensure comments are valid JSONC if your toolchain supports them.","Re-run `astro add <integration>` once the JSON parses cleanly.","If unsure, snapshot the file, replace with a minimal valid tsconfig, and re-apply your customizations after `astro add` finishes.","Check for a stray BOM: `file tsconfig.json` should say ASCII/UTF-8, not `UTF-8 Unicode (with BOM)`."],"exampleFix":"// before — tsconfig.json\n{\n  \"compilerOptions\": {\n    \"strict\": true,   // trailing comma + comment\n  }\n}\n\n// after\n{\n  \"compilerOptions\": {\n    \"strict\": true\n  }\n}","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction tsconfigIsValidJson(path: string): boolean {\n  const txt = readFileSync(path, 'utf8').replace(/\\/\\/.*$/gm, '').replace(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n  try { JSON.parse(txt); return true; } catch { return false; }\n}","typeGuard":"function isParsableConfig(raw: string): boolean {\n  try { JSON.parse(raw.replace(/\\/\\/.*$/gm,'').replace(/\\/\\*[\\s\\S]*?\\*\\//g,'').replace(/,\\s*([}\\]])/g,'$1')); return true; }\n  catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Run `tsc --noEmit` before `astro add` to surface config errors.","Avoid hand-editing tsconfig with trailing commas or single quotes.","Use a JSON-aware editor and keep comments consistent with JSONC support."],"tags":["cli","astro-add","tsconfig","configuration"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}