angular/components · error · SchematicsException
Could not find project in workspace: ${projectName}
Error message
Could not find project in workspace: ${projectName} What it means
getProjectFromWorkspace in src/cdk/schematics/utils/get-project.ts looks up a project by name in the Angular workspace definition read from angular.json. When workspace.projects.get(projectName) returns undefined, the schematic aborts with this SchematicsException. The library throws it because schematics cannot safely proceed operating on a project that does not exist in the workspace config.
Source
Thrown at src/cdk/schematics/utils/get-project.ts:29
/**
* Finds the specified project configuration in the workspace. Throws an error if the project
* couldn't be found.
*/
export function getProjectFromWorkspace(
workspace: WorkspaceDefinition,
projectName: string | undefined,
): ProjectDefinition {
if (!projectName) {
// TODO(crisbeto): some schematics APIs have the project name as optional so for now it's
// simpler to allow undefined and checking it at runtime. Eventually we should clean this up.
throw new SchematicsException('Project name is required.');
}
const project = workspace.projects.get(projectName);
if (!project) {
throw new SchematicsException(`Could not find project in workspace: ${projectName}`);
}
return project;
}
View on GitHub (pinned to 0411926e7d)
Solutions
- Run `ng json-schema 2>/dev/null; cat angular.json` (or open angular.json) and list the exact keys under "projects"; use one of those names for --project.
- Omit the --project flag so the schematic falls back to the default project defined at the top level of angular.json.
- If the project was renamed, update npm scripts, CI pipelines, and docs to the new project name.
- If no angular.json exists (non-CLI repo), initialize a workspace with `ng new` / `ng generate config` before running the schematic.
Example fix
// before ng add @angular/material --project=my-frontend-app // after ng add @angular/material --project=my-frontend-app # where "my-frontend-app" matches a key in angular.json "projects"
Defensive patterns
Strategy: validation
Validate before calling
const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));
const name = 'my-app';
if (!ws.projects || !(name in ws.projects)) {
throw new Error(`Project "${name}" not in angular.json. Available: ${Object.keys(ws.projects || {}).join(', ')}`);
} Type guard
function hasProject(ws: { projects?: Record<string, unknown> }, name: string): boolean {
return !!ws.projects && Object.prototype.hasOwnProperty.call(ws.projects, name);
} Try / catch
try {
await ngAdd(['@angular/material'], { project: name });
} catch (e) {
if (String(e.message).includes('Could not find project in workspace')) {
console.error(`Unknown project "${name}"; check angular.json "projects" keys.`);
} else throw e;
} Prevention
- Always copy the --project value from the exact key in angular.json, not a directory name.
- Update CI scripts whenever a project is renamed in the workspace.
- Prefer omitting --project and relying on the defaultProject when operating on a single-app workspace.
When it happens
Trigger: Calling a schematic (e.g. ng add @angular/material, or internal project()/addFontsToIndex flows) with --project=<name> where <name> is not a key under "projects" in angular.json/workspace.json; passing a library target name where an application is expected; running the schematic outside an Angular CLI workspace so no projects are registered.
Common situations: Typo in the --project flag; renamed project in angular.json but old name in npm scripts/CI; multi-app monorepos where the schematic defaults to a name that was removed; running schematics in a repo where angular.json lives in a subdirectory.
Related errors
- Could not find the project main file inside of the workspace
- Cannot determine project target configuration for: ${buildTa
- Cannot read "${filePath}" because it does not exist.
- No data could be found for target version: ${version}
- Could not find file for path: ${path}
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/e772c24a9f687677.
Report an issue: GitHub.