{"record":{"id":"fa899ca5050a4275","repo":"react/create-react-app","slug":"ts-formatdiagnostic-error-formatdiagnostichost","errorCode":null,"errorMessage":"ts.formatDiagnostic(error, formatDiagnosticHost)","messagePattern":"ts\\.formatDiagnostic\\(error, formatDiagnosticHost\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js","lineNumber":179,"sourceCode":"\n  const formatDiagnosticHost = {\n    getCanonicalFileName: fileName => fileName,\n    getCurrentDirectory: ts.sys.getCurrentDirectory,\n    getNewLine: () => os.EOL,\n  };\n\n  const messages = [];\n  let appTsConfig;\n  let parsedTsConfig;\n  let parsedCompilerOptions;\n  try {\n    const { config: readTsConfig, error } = ts.readConfigFile(\n      paths.appTsConfig,\n      ts.sys.readFile\n    );\n\n    if (error) {\n      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(","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/react/create-react-app/blob/6254386531d263688ccfa542d0e628fbc0de0b28/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js#L161-L197","documentation":"verifyTypeScriptSetup reads tsconfig.json via ts.readConfigFile. If TypeScript itself reports an error reading the file (e.g. the file is missing, unreadable, or contains content readConfigFile flags as an error), that diagnostic is formatted into a string and thrown. This is the first of two tsconfig gates in the try block.","triggerScenarios":"Running tsc-based type checking (react-scripts build/test with TypeScript) when ts.readConfigFile returns a non-null `error` object for paths.appTsConfig. The `if (error)` branch formats the diagnostic and throws.","commonSituations":"tsconfig.json deleted or renamed after being referenced. File permissions prevent reading. A JSON syntax error that readConfigFile surfaces as a diagnostic. An invalid `extends` target that readConfigFile cannot resolve.","solutions":["Ensure tsconfig.json exists at the project root and is readable.","Validate the JSON syntax with a linter or `npx tsc --noEmit` to surface the exact diagnostic.","If using `extends`, confirm the base config path resolves (e.g. tsconfig.json from react-scripts or a shared config exists).","Restore tsconfig.json from version control if it was deleted."],"exampleFix":"// before\ntsconfig.json: { \"extends\": \"./nonexistent/base.json\", \"compilerOptions\": {} }\n// after\ntsconfig.json: { \"extends\": \"react-scripts/tsconfig.json\", \"compilerOptions\": {} }","handlingStrategy":"try-catch","validationCode":"const fs = require('fs');\nconst ts = require('typescript');\nfunction preflightReadTsConfig(tsConfigPath) {\n  if (!fs.existsSync(tsConfigPath)) {\n    throw new Error(`tsconfig.json missing at ${tsConfigPath}`);\n  }\n  const { error } = ts.readConfigFile(tsConfigPath, ts.sys.readFile);\n  if (error) {\n    throw new Error(ts.formatDiagnostic(error, formatHost));\n  }\n}\npreflightReadTsConfig(paths.appTsConfig);","typeGuard":"const tsConfigReadsClean = (p) => {\n  const { error } = ts.readConfigFile(p, ts.sys.readFile);\n  return !error;\n};","tryCatchPattern":"try {\n  require('react-scripts/scripts/utils/verifyTypeScriptSetup');\n} catch (e) {\n  if (/tsconfig\\.json|Could not parse/i.test(e.message)) {\n    console.error('tsconfig.json could not be read. Check syntax/exists/extends.');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Validate tsconfig.json with `npx tsc --noEmit` after edits.","Confirm any `extends` target exists and is a valid config.","Keep tsconfig.json under version control so deletions are visible.","Use a JSON schema in your editor for tsconfig to catch typos."],"tags":["typescript","config","tsconfig","diagnostic"],"backgroundTag":null,"analyzedSha":"6254386531d263688ccfa542d0e628fbc0de0b28","analyzedAt":"2026-08-12T22:55:01.751Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}