{"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":466,"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":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/cli/add/index.ts#L448-L484","documentation":"After `astro add` installs an integration, it updates tsconfig.json/jsconfig.json (e.g. setting jsx settings for React). If the updater returns 'failure' — the config file exists but could not be parsed or written — astro add throws this generic Error from packages/astro/src/cli/add/index.ts:465 instead of corrupting your file silently.","triggerScenarios":"Running `npx astro add react` (or similar) with a tsconfig.json containing invalid JSON/JSONC syntax; a config with stray trailing commas/comments that break the parser; file locked or with weird permissions; BOM or encoding issues; two config formats colliding (jsconfig.json and tsconfig.json both present).","commonSituations":"Hand-edited tsconfig with syntax errors; files written by other tools (editor plugins) with unusual formatting; monorepos sharing a base config with broken `extends`; a previous interrupted astro add leaving a malformed file.","solutions":["Open tsconfig.json (and jsconfig.json if present) and fix JSON/JSONC syntax errors — validate by parsing it (`npx tsc --noEmit` or an editor's JSON validator)","If the file is unrecoverable, back it up and regenerate a minimal tsconfig, then re-run `npx astro add <integration>`","As a fallback, add the integration's required compilerOptions manually (see the integration's docs) — astro add will then skip or succeed"],"exampleFix":"```jsonc\n// before: tsconfig.json (trailing comma)\n{ \"extends\": \"astro/tsconfigs/strict\", }\n\n// after\n{ \"extends\": \"astro/tsconfigs/strict\" }\n```","handlingStrategy":"try-catch","validationCode":"// validate the config file parses before running astro add\nimport { readFileSync } from 'node:fs';\nJSON.parse(readFileSync('tsconfig.json', 'utf8').replace(/\\/\\*[\\s\\S]*?\\*\\//g, '').replace(/(^|[^:])\\/\\/.*$/gm, '$1'));\nconsole.log('tsconfig.json parses ok');","typeGuard":null,"tryCatchPattern":"try {\n  await add(['react'], { yes: true });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Could not update TypeScript settings')) {\n    // add the jsx compilerOptions by hand, then continue\n    console.error('Fix tsconfig.json manually, then re-run astro add');\n  }\n  throw err;\n}","preventionTips":["Run `npx tsc --noEmit` (or an editor JSON validator) after editing tsconfig","Commit tsconfig before running astro add so failures are recoverable via git"],"tags":["astro","cli","astro-add","tsconfig","json","configuration"],"backgroundTag":"config-file-parse-error","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}