{"record":{"id":"eb8f4ca531e81972","repo":"react/create-react-app","slug":"ts-formatdiagnostic-result-errors-0-formatdiagno","errorCode":null,"errorMessage":"ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)","messagePattern":"ts\\.formatDiagnostic\\(result\\.errors\\[0\\], formatDiagnosticHost\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js","lineNumber":197,"sourceCode":"      throw new Error(ts.formatDiagnostic(error, formatDiagnosticHost));\n    }\n\n    appTsConfig = readTsConfig;\n\n    // Get TS to parse and resolve any \"extends\"\n    // Calling this function also mutates the tsconfig above,\n    // adding in \"include\" and \"exclude\", but the compilerOptions remain untouched\n    let result;\n    parsedTsConfig = immer(readTsConfig, config => {\n      result = ts.parseJsonConfigFileContent(\n        config,\n        ts.sys,\n        path.dirname(paths.appTsConfig)\n      );\n    });\n\n    if (result.errors && result.errors.length) {\n      throw new Error(\n        ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)\n      );\n    }\n\n    parsedCompilerOptions = result.options;\n  } catch (e) {\n    if (e && e.name === 'SyntaxError') {\n      console.error(\n        chalk.red.bold(\n          'Could not parse',\n          chalk.cyan('tsconfig.json') + '.',\n          'Please make sure it contains syntactically correct JSON.'\n        )\n      );\n    }\n\n    console.log(e && e.message ? `${e.message}` : '');\n    process.exit(1);","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/react/create-react-app/blob/6254386531d263688ccfa542d0e628fbc0de0b28/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js#L179-L215","documentation":"After reading tsconfig.json, verifyTypeScriptSetup calls ts.parseJsonConfigFileContent to resolve extends/include/exclude and compilerOptions. If that returns any errors (e.g. invalid compiler option, unresolvable path, bad include glob), the first error is formatted and thrown. This is the second, deeper tsconfig gate.","triggerScenarios":"tsconfig.json parses as JSON but its resolved content is invalid: an unknown compilerOptions key, an invalid `paths`/`baseUrl` combination, an unreachable `include`/`exclude` glob, or a circular/broken `extends`. result.errors is a non-empty array, so the throw fires.","commonSituations":"Hand-editing compilerOptions and introducing a typo (e.g. `target: esnextt`). Adding `paths` without `baseUrl`. Pointing `include` at a non-existent directory. Extending a config whose compilerOptions conflict. Upgrading TypeScript and using an option removed in the new version.","solutions":["Run `npx tsc --noEmit` to see the full list of config errors and address the first one.","If you added `paths`, ensure `baseUrl` is set (CRA supports `src`).","Check every compilerOptions key against the TypeScript reference for your TS version; remove/fix unknown ones.","Verify `include`/`exclude` glob patterns point to existing directories.","Simplify by removing `extends` temporarily to isolate whether the error comes from the base config."],"exampleFix":"// before  (tsconfig.json)\n{\n  \"compilerOptions\": { \"target\": \"esnextt\", \"paths\": { \"@/*\": [\"src/*\"] } }\n}\n// after\n{\n  \"compilerOptions\": { \"target\": \"esnext\", \"baseUrl\": \"src\", \"paths\": { \"@/*\": [\"./*\"] } }\n}","handlingStrategy":"try-catch","validationCode":"const ts = require('typescript');\nfunction preflightParseTsConfig(tsConfigPath) {\n  const { config } = ts.readConfigFile(tsConfigPath, ts.sys.readFile);\n  const result = ts.parseJsonConfigFileContent(\n    config, ts.sys, require('path').dirname(tsConfigPath)\n  );\n  if (result.errors && result.errors.length) {\n    throw new Error(ts.formatDiagnostic(result.errors[0], formatHost));\n  }\n}\npreflightParseTsConfig(paths.appTsConfig);","typeGuard":"const tsConfigParsesClean = (p) => {\n  const { config } = ts.readConfigFile(p, ts.sys.readFile);\n  const { errors } = ts.parseJsonConfigFileContent(config, ts.sys, require('path').dirname(p));\n  return !errors || errors.length === 0;\n};","tryCatchPattern":"try {\n  require('react-scripts/scripts/utils/verifyTypeScriptSetup');\n} catch (e) {\n  if (/TS\\d+|compilerOptions|cannot be found/i.test(e.message)) {\n    console.error('tsconfig.json has invalid compilerOptions. Run `npx tsc --noEmit`.');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Run `npx tsc --noEmit` locally to surface all config diagnostics before building.","When adding `paths`, always set `baseUrl` (CRA supports 'src').","Cross-check compilerOptions against the TS version you depend on.","Introduce `extends` one step at a time to isolate bad inherited options."],"tags":["typescript","config","tsconfig","compileroptions","diagnostic"],"backgroundTag":null,"analyzedSha":"6254386531d263688ccfa542d0e628fbc0de0b28","analyzedAt":"2026-08-12T22:55:01.751Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}