{"record":{"id":"e772c24a9f687677","repo":"angular/components","slug":"could-not-find-project-in-workspace-projectname","errorCode":null,"errorMessage":"Could not find project in workspace: ${projectName}","messagePattern":"Could not find project in workspace: (.+?)","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"src/cdk/schematics/utils/get-project.ts","lineNumber":29,"sourceCode":"\n/**\n * Finds the specified project configuration in the workspace. Throws an error if the project\n * couldn't be found.\n */\nexport function getProjectFromWorkspace(\n  workspace: WorkspaceDefinition,\n  projectName: string | undefined,\n): ProjectDefinition {\n  if (!projectName) {\n    // TODO(crisbeto): some schematics APIs have the project name as optional so for now it's\n    // simpler to allow undefined and checking it at runtime. Eventually we should clean this up.\n    throw new SchematicsException('Project name is required.');\n  }\n\n  const project = workspace.projects.get(projectName);\n\n  if (!project) {\n    throw new SchematicsException(`Could not find project in workspace: ${projectName}`);\n  }\n\n  return project;\n}\n","sourceCodeStart":11,"sourceCodeEnd":34,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/schematics/utils/get-project.ts#L11-L34","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nng add @angular/material --project=my-frontend-app\n// after\nng add @angular/material --project=my-frontend-app  # where \"my-frontend-app\" matches a key in angular.json \"projects\"","handlingStrategy":"validation","validationCode":"const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));\nconst name = 'my-app';\nif (!ws.projects || !(name in ws.projects)) {\n  throw new Error(`Project \"${name}\" not in angular.json. Available: ${Object.keys(ws.projects || {}).join(', ')}`);\n}","typeGuard":"function hasProject(ws: { projects?: Record<string, unknown> }, name: string): boolean {\n  return !!ws.projects && Object.prototype.hasOwnProperty.call(ws.projects, name);\n}","tryCatchPattern":"try {\n  await ngAdd(['@angular/material'], { project: name });\n} catch (e) {\n  if (String(e.message).includes('Could not find project in workspace')) {\n    console.error(`Unknown project \"${name}\"; check angular.json \"projects\" keys.`);\n  } else throw e;\n}","preventionTips":["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."],"tags":["angular","schematics","workspace-config","angular-cli"],"backgroundTag":"project-not-found-in-workspace","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}