cypress-io/cypress · error · SchematicsException
File not found.
Error message
File not found.
What it means
Raised by the readFile() implementation inside createSpec() (cypress-test ng-generate schematic) when tree.read(path) returns a falsy value while the Angular workspaces.readWorkspace API tries to read a file from the virtual tree. readWorkspace walks the workspace and asks the host for files; if a referenced file is absent from the schematic tree, readFile throws this generic SchematicsException.
Source
Thrown at npm/cypress-schematic/src/schematics/ng-generate/cypress-test/index.ts:17
import {
Rule, Tree, SchematicsException, chain, mergeWith,
} from '@angular-devkit/schematics'
import { virtualFs, workspaces } from '@angular-devkit/core'
import { Schema } from './schema'
import { createTemplate } from '../../utils'
function createSpec (tree: Tree): workspaces.WorkspaceHost {
return {
async readFile (path: string): Promise<string> {
const data = tree.read(path)
if (!data) {
throw new SchematicsException('File not found.')
}
return virtualFs.fileBufferToString(data)
},
async writeFile (path: string, data: string): Promise<void> {
return tree.overwrite(path, data)
},
async isDirectory (path: string): Promise<boolean> {
return !tree.exists(path) && tree.getDir(path).subfiles.length > 0
},
async isFile (path: string): Promise<boolean> {
return tree.exists(path)
},
}
}
export default function (options: Schema): Rule {
return async (tree: Tree) => {View on GitHub (pinned to 0d85fdc912)
Solutions
- Ensure you run the schematic from the Angular workspace root and that angular.json plus all referenced files exist.
- Run `ng config` or `ng generate component --dry-run` to confirm Angular itself can read the workspace.
- Restore any missing workspace files from version control before re-running the schematic.
- Validate that the tree actually contains the file path reported (enable schematic debug logging) and fix the workspace reference.
Example fix
// before: angular.json references a deleted tsconfig, schematic throws 'File not found.' // after: restore the referenced tsconfig (or remove the dangling reference), then re-run the schematic
Defensive patterns
Strategy: validation
Validate before calling
// Before triggering the schematic, ensure angular.json and referenced files exist:
import fs from 'fs'
const required = ['./angular.json']
for (const f of required) {
if (!fs.existsSync(f)) {
throw new Error(`Missing workspace file required by the schematic: ${f}`)
}
} Try / catch
try {
await runSchematic('cypress-test', opts)
} catch (e) {
if (e instanceof SchematicsException && /File not found/.test(e.message)) {
// a workspace file referenced by angular.json is missing — restore it, then retry
}
throw e
} Prevention
- Run the schematic from the Angular workspace root.
- Ensure angular.json references only files that exist.
- Validate the workspace with `ng config` before generating.
When it happens
Trigger: Running `ng generate @cypress/schematic:cypress-test` when the workspace references a file (commonly angular.json itself or a referenced tsconfig/schematics file) that is not present in the tree — e.g. corrupted workspace, a file deleted between parsing and generation, or a non-standard workspace layout.
Common situations: A workspace with a manually edited angular.json pointing at missing files; running the schematic from the wrong directory so relative paths do not resolve; an Angular CLI version that reads additional config files the workspace does not have; partial git checkout missing workspace files.
Related errors
- Invalid project name: ${options.project}
- Invalid project name: ${options.project}
- No file name specified. This is required to generate a new C
- projects in angular.json is not defined
- angular.json not found
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/d2246d44d8d1fc9e.
Report an issue: GitHub.