cypress-io/cypress · error · Error
Could not read '${path}'.
Error message
Could not read '${path}'. What it means
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.
Source
Thrown at npm/cypress-schematic/src/schematics/utils/jsonFile.ts:36
parseTree,
printParseErrorCode,
} from 'jsonc-parser'
export type InsertionIndex = (properties: string[]) => number
export type JSONPath = (string | number)[]
/** @internal */
export class JSONFile {
content: string
constructor (private readonly host: Tree, private readonly path: string) {
const buffer = this.host.read(this.path)
if (buffer) {
this.content = buffer.toString()
} else {
throw new Error(`Could not read '${path}'.`)
}
}
private _jsonAst: Node | undefined
private get JsonAst (): Node | undefined {
if (this._jsonAst) {
return this._jsonAst
}
const errors: ParseError[] = []
this._jsonAst = parseTree(this.content, errors, { allowTrailingComma: true })
if (errors.length) {
const { error, offset } = errors[0]
throw new Error(
`Failed to parse "${this.path}" as JSON AST Object. ${printParseErrorCode(
error,View on GitHub (pinned to 0d85fdc912)
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.
Example fix
// before: run from /packages/frontend while angular.json lives at repo root ng add @cypress/schematic // after: run from the workspace root that contains angular.json cd /repo-root && ng add @cypress/schematic
Defensive patterns
Strategy: validation
Validate before calling
// before constructing JSONFile in a schematic
import { existsSync } from './exists';
function readJsonSafe(host: Tree, p: string) {
if (!host.exists(p)) { // DevKit Tree has exists()
throw new Error(`Refusing to open missing file: ${p}`)
}
return new JSONFile(host, p)
} Type guard
const isReadablePath = (host: Tree, p: string): boolean => typeof p === 'string' && p.length > 0 && !!host.exists && host.exists(p)
Try / catch
try {
const f = new JSONFile(host, path)
// ... mutate f
} catch (e) {
if (e instanceof Error && e.message.startsWith("Could not read")) {
// graceful: skip this file, log, or prompt user
} else throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to parse "${this.path}" as JSON AST Object. ${printPa
- projects in angular.json is not defined
- angular.json not found
- Invalid project name: ${options.project}
- File not found.
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/5c46a58b81891ef3.
Report an issue: GitHub.