{"record":{"id":"737ac9b3fae24b55","repo":"angular/components","slug":"project-name-is-required","errorCode":null,"errorMessage":"Project name is required.","messagePattern":"Project name is required\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"src/cdk/schematics/utils/get-project.ts","lineNumber":23,"sourceCode":" * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {SchematicsException} from '@angular-devkit/schematics';\nimport {ProjectDefinition, WorkspaceDefinition} from '@schematics/angular/utility';\n\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":5,"sourceCodeEnd":34,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/schematics/utils/get-project.ts#L5-L34","documentation":"getProjectFromWorkspace receives projectName as string | undefined because some schematic APIs allow optional project names; when it is undefined/empty the function throws this SchematicsException instead of silently guessing the default project.","triggerScenarios":"Calling getProjectFromWorkspace(workspace, options.project) where options.project is undefined — e.g. the schematic's schema doesn't declare a 'project' property with a default, the user omitted --project and no default was injected, or 'project' is an empty string.","commonSituations":"Custom schematics that call this util without registering the project option in schema.json, running `ng add`/`ng generate` in workspaces where the caller forgot --project, and newer Angular CLI versions (13+ WorkspaceDefinition API) where defaults are no longer auto-resolved by the util.","solutions":["Pass --project=<name> explicitly on the schematic command line.","In your schematic, default the option before calling: projectName ?? workspace.extensions.defaultProject (or first entry of workspace.projects).","Add a 'project' property with `$default: { \"$source\": \"projectName\" }` to the schematic's schema.json so the CLI injects it.","Ensure the workspace config defines a defaultProject so the CLI's project-name source resolves."],"exampleFix":"// before\nconst project = getProjectFromWorkspace(workspace, options.project); // options.project: string | undefined\n// after\nconst projectName = options.project ?? (workspace.extensions['defaultProject'] as string | undefined);\nconst project = getProjectFromWorkspace(workspace, projectName);","handlingStrategy":"validation","validationCode":"function resolveProjectName(\n  projectName: string | undefined,\n  workspace: WorkspaceDefinition,\n): string {\n  const fallback = workspace.extensions['defaultProject'] as string | undefined;\n  const name = projectName ?? fallback;\n  if (!name) {\n    throw new Error('No --project given and no defaultProject in angular.json');\n  }\n  return name;\n}","typeGuard":"function hasProjectName(p: string | undefined): p is string {\n  return typeof p === 'string' && p.trim().length > 0;\n}","tryCatchPattern":"try {\n  const project = getProjectFromWorkspace(workspace, options.project);\n} catch (e) {\n  if (e instanceof SchematicsException && e.message === 'Project name is required.') {\n    console.error('Pass --project=<name> to the schematic.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Always pass --project in multi-project workspaces.","Declare the project option in schema.json with $default projectName source.","Default options.project to the workspace defaultProject in your schematic's rule factory.","Reject empty-string project names early at the CLI/option-parsing layer."],"tags":["angular","schematics","configuration","workspace"],"backgroundTag":"missing-project-name","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}