Skip to content
Latchkey

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.

tsc output
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

  1. Open tsconfig.json at the line/column in the error and remove the trailing comma or fix the token.
  2. Quote all keys and string values with double quotes; comments are allowed, single quotes are not.
  3. 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.

Terminal
npx tsc --showConfig -p tsconfig.json   # errors loudly on invalid JSON

How to prevent it

  • Keep tsconfig.json valid JSONC - no trailing commas or unquoted keys.
  • Let an editor/formatter validate JSON on save.
  • Run tsc --showConfig in CI to fail fast on config syntax errors.

Frequently asked questions

What causes ""Failed to parse" tsconfig"?
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.
How do I fix "Failed to parse" tsconfig?
Fix the JSON at the reported position

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card