{"record":{"id":"5c46a58b81891ef3","repo":"cypress-io/cypress","slug":"could-not-read-path","errorCode":null,"errorMessage":"Could not read '${path}'.","messagePattern":"Could not read '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/cypress-schematic/src/schematics/utils/jsonFile.ts","lineNumber":36,"sourceCode":"  parseTree,\n  printParseErrorCode,\n} from 'jsonc-parser'\n\nexport type InsertionIndex = (properties: string[]) => number\n\nexport type JSONPath = (string | number)[]\n\n/** @internal */\nexport class JSONFile {\n  content: string\n\n  constructor (private readonly host: Tree, private readonly path: string) {\n    const buffer = this.host.read(this.path)\n\n    if (buffer) {\n      this.content = buffer.toString()\n    } else {\n      throw new Error(`Could not read '${path}'.`)\n    }\n  }\n\n  private _jsonAst: Node | undefined\n  private get JsonAst (): Node | undefined {\n    if (this._jsonAst) {\n      return this._jsonAst\n    }\n\n    const errors: ParseError[] = []\n\n    this._jsonAst = parseTree(this.content, errors, { allowTrailingComma: true })\n    if (errors.length) {\n      const { error, offset } = errors[0]\n\n      throw new Error(\n         `Failed to parse \"${this.path}\" as JSON AST Object. ${printParseErrorCode(\n           error,","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/cypress-io/cypress/blob/0d85fdc91230885bca0a91df278312800a48b727/npm/cypress-schematic/src/schematics/utils/jsonFile.ts#L18-L54","documentation":"Thrown by the JSONFile constructor in @cypress/schematic when the Angular DevKit Tree host returns a falsy buffer for the requested path. The schematic relies on host.read() to load JSON files (package.json, angular.json, tsconfig.json) it must mutate; a null/undefined buffer means the file does not exist at that path in the virtual filesystem the schematic operates on. The message interpolates the constructor's `path` argument so you can see which file was missing.","triggerScenarios":"Instantiating `new JSONFile(host, path)` where `host.read(path)` returns null or undefined. Happens during `ng add @cypress/schematic` when a JSON file the schematic expects (e.g. tsconfig.json or package.json) is absent, misnamed, outside the workspace root, or when the schematic was pointed at a path the Tree cannot resolve.","commonSituations":"Running the schematic in a non-standard Angular workspace (e.g. an Nx monorepo, a workspace with package.json at a different level), running against a project that never ran `npm init`, or after a partial workspace where the schematic's target file was deleted/moved. Also seen when the schematic version expects a file the user's Angular version does not generate.","solutions":["Verify the file named in the error message actually exists at the workspace root (e.g. `ls package.json angular.json tsconfig.json`).","Ensure you run `ng add @cypress/schematic` from the Angular workspace root, not a subdirectory or the parent folder.","If the file legitimately does not exist (e.g. a minimal project), create a minimal valid JSON file at the path before re-running the schematic.","Update @cypress/schematic to the latest version compatible with your Angular CLI major version."],"exampleFix":"// before: run from /packages/frontend while angular.json lives at repo root\nng add @cypress/schematic\n// after: run from the workspace root that contains angular.json\ncd /repo-root && ng add @cypress/schematic","handlingStrategy":"validation","validationCode":"// before constructing JSONFile in a schematic\nimport { existsSync } from './exists';\nfunction readJsonSafe(host: Tree, p: string) {\n  if (!host.exists(p)) { // DevKit Tree has exists()\n    throw new Error(`Refusing to open missing file: ${p}`)\n  }\n  return new JSONFile(host, p)\n}","typeGuard":"const isReadablePath = (host: Tree, p: string): boolean => typeof p === 'string' && p.length > 0 && !!host.exists && host.exists(p)","tryCatchPattern":"try {\n  const f = new JSONFile(host, path)\n  // ... mutate f\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Could not read\")) {\n    // graceful: skip this file, log, or prompt user\n  } else throw e\n}","preventionTips":["Validate file existence with host.exists(path) before constructing JSONFile.","Run schematics from the workspace root that contains angular.json/package.json.","Pre-check required files in the schematic's factory before passing them to JSONFile."],"tags":["angular","schematic","json","filesystem","config"],"backgroundTag":null,"analyzedSha":"0d85fdc91230885bca0a91df278312800a48b727","analyzedAt":"2026-08-12T16:24:28.056Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}