cypress-io/cypress · error · SchematicsException
projects in angular.json is not defined
Error message
projects in angular.json is not defined
What it means
Raised by modifyAngularJson() during `ng add @cypress/schematic` when angular.json exists and was parsed, but its top-level `projects` key is missing or falsy. The schematic iterates Object.keys(projects) to add cypress-run/cypress-open (and optionally e2e/ct) targets per project, so without that key it cannot proceed and aborts with a SchematicsException.
Source
Thrown at npm/cypress-schematic/src/schematics/ng-add/index.ts:229
if (component) {
projectArchitectJson['ct'] = componentJson
}
if (e2e || !projectArchitectJson['e2e']) {
projectArchitectJson['e2e'] = e2eJson
}
return tree.overwrite('./angular.json', JSON.stringify(angularJsonVal, null, 2))
}
function modifyAngularJson (options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
if (tree.exists('./angular.json')) {
const angularJsonVal = getAngularJsonValue(tree)
const { projects } = angularJsonVal
if (!projects) {
throw new SchematicsException('projects in angular.json is not defined')
}
Object.keys(projects).forEach((project) => {
const builder = '@cypress/schematic:cypress'
const runJson = {
builder,
options: {
devServerTarget: `${project}:serve`,
},
configurations: {
production: {
devServerTarget: `${project}:serve:production`,
},
},
}
const openJson = {
builder,View on GitHub (pinned to 0d85fdc912)
Solutions
- Open angular.json and ensure it has a top-level `projects` object listing at least one project (the standard Angular CLI shape).
- If the workspace is not a real Angular CLI workspace, create one with `ng new` or run the schematic from the directory that actually holds angular.json.
- Run `ng add @cypress/schematic` from the project root where the well-formed angular.json lives.
- Validate angular.json with `ng config` or by running any standard `ng generate` command to confirm Angular accepts it.
Example fix
// before: angular.json has no "projects" key
// after:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"app": { /* ... */ }
}
} Defensive patterns
Strategy: validation
Validate before calling
import { getAngularJsonValue } from '../../utils'
function assertHasProjects(tree: Tree) {
const { projects } = getAngularJsonValue(tree)
if (!projects) {
throw new Error('angular.json is missing a top-level "projects" object')
}
return projects
} Type guard
function hasProjects(json: any): json is { projects: Record<string, unknown> } {
return Boolean(json && typeof json === 'object' && json.projects && typeof json.projects === 'object')
} Prevention
- Ensure angular.json conforms to the Angular CLI schema (with a projects object) before running ng add.
- Run `ng config` to validate the workspace.
- Create workspaces with `ng new` to guarantee the correct shape.
When it happens
Trigger: Running `ng add @cypress/schematic` in a workspace whose angular.json has no `projects` field — e.g. a hand-edited or partially generated angular.json, a non-Angular workspace with a stray angular.json, or a malformed JSON where projects was deleted.
Common situations: A workspace not created with `ng new`; manual edits that removed projects; an Angular CLI version that wrote an unexpected angular.json shape; a monorepo where the real Angular workspace lives in a subdirectory.
Related errors
- angular.json not found
- Invalid project name: ${options.project}
- File not found.
- Invalid project name: ${options.project}
- No file name specified. This is required to generate a new C
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/762e315456533df4.
Report an issue: GitHub.