withastro/astro · error · Error
Unknown error parsing tsconfig.json or jsconfig.json. Could
Error message
Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.
What it means
`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.
Source
Thrown at packages/astro/src/cli/add/index.ts:465
}
const updateTSConfigResult = await updateTSConfig(cwd, logger, integrations, flags, {
addIncludes: hasCloudflareIntegration ? ['./worker-configuration.d.ts'] : [],
});
switch (updateTSConfigResult) {
case 'none': {
break;
}
case 'cancelled': {
logger.info(
'SKIP_FORMAT',
msg.cancelled(`Your TypeScript configuration has ${bold('NOT')} been updated.`),
);
break;
}
case 'failure': {
throw new Error(
`Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.`,
);
}
case 'updated':
logger.info('SKIP_FORMAT', msg.success(`Successfully updated tsconfig`));
}
}
function isAdapter(
integration: IntegrationInfo,
): integration is IntegrationInfo & { type: 'adapter' } {
return integration.type === 'adapter';
}
// Convert an arbitrary NPM package name into a JS identifier
// Some examples:
// - @astrojs/image => image
// - @astrojs/markdown-component => markdownComponentView on GitHub (pinned to d081033d5f)
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)`.
Example fix
// before — tsconfig.json
{
"compilerOptions": {
"strict": true, // trailing comma + comment
}
}
// after
{
"compilerOptions": {
"strict": true
}
} Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'node:fs';
function tsconfigIsValidJson(path: string): boolean {
const txt = readFileSync(path, 'utf8').replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, '');
try { JSON.parse(txt); return true; } catch { return false; }
} Type guard
function isParsableConfig(raw: string): boolean {
try { JSON.parse(raw.replace(/\/\/.*$/gm,'').replace(/\/\*[\s\S]*?\*\//g,'').replace(/,\s*([}\]])/g,'$1')); return true; }
catch { return false; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${integration} does not appear to be a valid package name!
- No problem! Find our official integrations at https://astro.
- Unable to fetch ${integration}. Does the package exist?
- ${packageName} doesn't appear to be an integration or an ada
- `--ignore-lock` cannot be used together with `--background`.
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/77c4a2cdf142bae7.
Report an issue: GitHub.