TypeScript "Failed to parse file" - Fix tsconfig.json JSON Errors
tsc could not parse tsconfig.json itself because it is not valid JSON(C). A trailing comma, an unquoted key, or a stray character breaks parsing before any option is read.
What this error means
tsc fails at config load with a parse error pointing inside tsconfig.json (e.g. error TS1005: ',' expected or Failed to parse file). No compilation happens because the config never loads.
error TS1005: ',' expected.
tsconfig.json:7:4
"strict": true,
"noEmit": true,
}
~Common causes
Invalid JSON syntax
A trailing comma after the last property, a missing comma between properties, an unquoted key, or single quotes makes the file invalid JSON. tsconfig allows comments (JSONC) but not these.
Hidden/non-ASCII characters
A BOM, a smart quote pasted from a doc, or a stray control character corrupts the file so the parser rejects it, even though it looks fine in an editor.
How to fix it
Fix the JSON at the reported position
- Open
tsconfig.jsonat the line/column in the error and remove the trailing comma or fix the token. - Quote all keys and string values with double quotes; comments are allowed, single quotes are not.
- Strip any BOM or smart quotes introduced by copy-paste.
Validate the config in CI
Catch malformed config before it reaches the type-check step.
npx tsc --showConfig -p tsconfig.json # errors loudly on invalid JSONHow to prevent it
- Keep
tsconfig.jsonvalid JSONC - no trailing commas or unquoted keys. - Let an editor/formatter validate JSON on save.
- Run
tsc --showConfigin CI to fail fast on config syntax errors.