{"record":{"id":"28da9514f71494d0","repo":"withastro/astro","slug":"couldn-t-parse-tsconfig-json-or-jsconfig-json-i","errorCode":null,"errorMessage":"Couldn't parse tsconfig.json or jsconfig.json: ${inputConfig.message}","messagePattern":"Couldn't parse tsconfig\\.json or jsconfig\\.json: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/astro/src/cli/add/index.ts","lineNumber":983,"sourceCode":"\toptions?: { addIncludes?: string[] },\n): Promise<UpdateResult> {\n\tconst integrations = integrationsInfo.map(\n\t\t(integration) => integration.id as frameworkWithTSSettings,\n\t);\n\tconst includesToAppend = Array.from(new Set((options?.addIncludes ?? []).filter(Boolean)));\n\tconst firstIntegrationWithTSSettings = integrations.find((integration) =>\n\t\tpresets.has(integration),\n\t);\n\n\tif (!firstIntegrationWithTSSettings && includesToAppend.length === 0) {\n\t\treturn 'none';\n\t}\n\n\tlet inputConfig = await loadTSConfig(cwd);\n\tlet inputConfigText = '';\n\n\tif (inputConfig.error === 'invalid-config') {\n\t\tlogger.warn(`add`, `Couldn't parse tsconfig.json or jsconfig.json: ${inputConfig.message}`);\n\t\treturn 'failure';\n\t} else if (inputConfig.error === 'missing-config') {\n\t\tlogger.debug('add', \"Couldn't find tsconfig.json or jsconfig.json, generating one\");\n\t\tconst tsconfigFile = path.join(cwd, 'tsconfig.json');\n\t\tinputConfig = {\n\t\t\ttsconfig: defaultTSConfig,\n\t\t\ttsconfigFile: tsconfigFile,\n\t\t\trawConfig: defaultTSConfig,\n\t\t\tsources: [tsconfigFile],\n\t\t};\n\t} else {\n\t\tinputConfigText = JSON.stringify(inputConfig.rawConfig, null, 2);\n\t}\n\n\tconst configFileName = path.basename(inputConfig.tsconfigFile);\n\n\tlet outputConfig = firstIntegrationWithTSSettings\n\t\t? updateTSConfigForFramework(inputConfig.rawConfig, firstIntegrationWithTSSettings)","sourceCodeStart":965,"sourceCodeEnd":1001,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/cli/add/index.ts#L965-L1001","documentation":"When `astro add <integration>` syncs editor settings, it loads your tsconfig.json (or jsconfig.json). If TypeScript reports parse diagnostics — broken JSON syntax or an unresolvable `extends` — Astro logs this warning and returns 'failure': your tsconfig was NOT updated, so the integration's compiler options and generated typings were not wired up. The rest of `astro add` (dependency install, astro.config edit) still completes; only the TS-config step is skipped.","triggerScenarios":"Running `astro add` in a project whose tsconfig.json has a syntax error (missing brace/quote, stray comma, leftover merge-conflict markers) or an `extends` pointing at a package/file that does not exist.","commonSituations":"Hand-edited tsconfig with a typo; merge conflicts resolved badly; `extends` referencing an uninstalled base config; the file sits outside common JSONC pitfalls but contains genuine garbage.","solutions":["Surface the syntax error: `npx tsc -p . --noEmit` or `npx astro check` — both parse the config and report the offending line","Fix the JSON syntax (or install the missing `extends` package), then rerun `astro add <integration>`","Confirm the rerun actually patched tsconfig (astro add prints the diff it intends to apply)","If you intentionally skip TS setup, the warning is harmless — integrate typings manually via a reference to the integration's types"],"exampleFix":"// before: tsconfig.json with a syntax error\n{ \"extends\": \"astro/tsconfigs/strict\", }  // trailing junk or missing brace\n\n// after\n{ \"extends\": \"astro/tsconfigs/strict\" }","handlingStrategy":"validation","validationCode":"// Run before `astro add` to catch a broken config early\nimport { readFileSync } from 'node:fs';\nimport ts from 'typescript';\nconst parsed = ts.readConfigFile('tsconfig.json', ts.sys.readFile);\nif (parsed.error) {\n  console.error(ts.flattenDiagnosticMessageText(parsed.error, '\\n'));\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep tsconfig.json valid JSONC — no stray characters beyond comments","Add `astro check` or `tsc -p .` to CI so config parse errors surface before astro add runs","After astro add reports 'failure', always rerun it once the config is fixed — the sync step never retried itself"],"tags":["cli","astro-add","tsconfig","json"],"backgroundTag":"tsconfig-parse-error","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}