{"record":{"id":"6f0ad59292e42dc6","repo":"angular/angular-cli","slug":"formatdiagnostics-configresult-errors","errorCode":null,"errorMessage":"${formatDiagnostics(configResult.errors)}","messagePattern":"\\$\\{formatDiagnostics\\(configResult\\.errors\\)\\}","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/utils/read-tsconfig.ts","lineNumber":29,"sourceCode":"\n/**\n * Reads and parses a given TsConfig file.\n *\n * @param tsconfigPath - An absolute or relative path from 'workspaceRoot' of the tsconfig file.\n * @param workspaceRoot - workspaceRoot root location when provided\n * it will resolve 'tsconfigPath' from this path.\n */\nexport async function readTsconfig(\n  tsconfigPath: string,\n  workspaceRoot?: string,\n): Promise<ParsedConfiguration> {\n  const tsConfigFullPath = workspaceRoot ? path.resolve(workspaceRoot, tsconfigPath) : tsconfigPath;\n\n  const { formatDiagnostics, readConfiguration } = await import('@angular/compiler-cli');\n\n  const configResult = readConfiguration(tsConfigFullPath);\n  if (configResult.errors && configResult.errors.length) {\n    throw new Error(formatDiagnostics(configResult.errors));\n  }\n\n  return configResult;\n}\n","sourceCodeStart":11,"sourceCodeEnd":34,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/utils/read-tsconfig.ts#L11-L34","documentation":"readTsconfig delegates parsing and validation of the TypeScript configuration file to @angular/compiler-cli's readConfiguration. If the compiler-cli reports configuration errors (parse errors, invalid options, missing extends targets), the formatted diagnostics are thrown as a single Error. This is the Angular build system's way of surfacing TypeScript config problems before compilation starts.","triggerScenarios":"Calling readTsconfig with a tsconfig path whose JSON is syntactically invalid (comments/trailing commas without JSON5 support, BOM issues), references an 'extends' file that doesn't exist, or contains compilerOptions values rejected by the TypeScript version bundled with the CLI.","commonSituations":"Typo in angular.json tsConfig path pointing at the wrong file, tsconfig.extends pointing at a deleted base config, incompatible compilerOptions after a TypeScript upgrade (e.g. removed 'target' values), hand-edited tsconfig with a stray comma.","solutions":["Read the diagnostics in the error message — they name the exact file and JSON path of each config error","Fix the reported tsconfig errors (syntax, missing extends target, invalid compilerOptions)","Confirm the tsConfig path in angular.json resolves to an existing file relative to the workspace root","Align your TypeScript version with the one supported by your @angular-devkit/build_angular version"],"exampleFix":"// before\nclass App { }\n// after\nexport class App { }","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'fs';\nimport * as JSONC from 'jsonc-parser';\nconst raw = readFileSync(tsconfigPath, 'utf8');\nconst errors: any[] = [];\nJSONC.parse(raw, errors, { allowTrailingComma: true });\nif (errors.length) throw new Error(`Invalid tsconfig ${tsconfigPath}: ${errors.map(e => e.error).join(', ')}`);\n// also check extends target exists:\nconst cfg = JSONC.parse(raw);\nif (cfg.extends && !require('fs').existsSync(require('path').resolve(require('path').dirname(tsconfigPath), cfg.extends))) {\n  throw new Error(`tsconfig extends target not found: ${cfg.extends}`);\n}","typeGuard":"function isTsConfigResult(r: unknown): r is { options: ts.CompilerOptions; fileNames: string[]; errors: ts.Diagnostic[] } {\n  return !!r && typeof r === 'object' && 'options' in r && 'fileNames' in r;\n}","tryCatchPattern":"let config;\ntry {\n  config = await readTsconfig(tsconfigPath);\n} catch (e) {\n  // message contains formatted TS diagnostics; log and surface to user\n  console.error('tsconfig invalid:', (e as Error).message);\n  process.exit(1);\n}","preventionTips":["Validate tsconfig files in CI with `tsc --noEmit -p tsconfig.json` before running Angular builds","Use jsoncParser/schema validation when generating tsconfigs programmatically","Keep TypeScript version aligned with the Angular CLI major version","Don't hand-edit generated tsconfigs; fix the generator"],"tags":["typescript","tsconfig","configuration","diagnostics"],"backgroundTag":"tsconfig-parse-error","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}