angular/angular-cli · error · Error
Project "${projectName}" does not exist.
Error message
Project "${projectName}" does not exist. What it means
createDefaultPath looks up the given project in the workspace definition (angular.json) to compute its default source path. If the workspace has no project with that name, it throws this plain Error. The schematics (module, pipe, generateFromFiles) call it to determine where to place generated files.
Source
Thrown at packages/schematics/angular/utility/workspace.ts:130
}
/**
* Build a default project path for generating.
* @param project The project which will have its default path generated.
*/
export function buildDefaultPath(project: workspaces.ProjectDefinition): string {
const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`;
const projectDirName =
project.extensions['projectType'] === ProjectType.Application ? 'app' : 'lib';
return `${root}${projectDirName}`;
}
export async function createDefaultPath(tree: Tree, projectName: string): Promise<string> {
const workspace = await getWorkspace(tree);
const project = workspace.projects.get(projectName);
if (!project) {
throw new Error(`Project "${projectName}" does not exist.`);
}
return buildDefaultPath(project);
}
export function* allWorkspaceTargets(
workspace: workspaces.WorkspaceDefinition,
): Iterable<[string, workspaces.TargetDefinition, string, workspaces.ProjectDefinition]> {
for (const [projectName, project] of workspace.projects) {
for (const [targetName, target] of project.targets) {
yield [targetName, target, projectName, project];
}
}
}
export function* allTargetOptions(
target: workspaces.TargetDefinition,
skipBaseOptions = false,View on GitHub (pinned to bb72145f9a)
Solutions
- Run `ng generate module my-module --project=<exact-name>` using a name listed under "projects" in angular.json (`ng config projects` or open the file to check).
- Fix the defaultProject / workspace context: run the command from the repository root that contains angular.json.
- Add the missing project to angular.json if it should exist (or restore a deleted project block).
- Omit --project so the CLI uses the single/default project when only one exists.
Example fix
// before ng generate module shared --project=shard-lib // after ng generate module shared --project=shared-lib
Defensive patterns
Strategy: validation
Validate before calling
import { workspaces } from '@angular-devkit/core';
import * as fs from 'fs';
const cfg = JSON.parse(fs.readFileSync('angular.json', 'utf8'));
if (!cfg.projects?.[projectName]) {
throw new Error(`Project "${projectName}" not found. Available: ${Object.keys(cfg.projects).join(', ')}`);
} Try / catch
try {
await ngGenerate(['module', 'shared', '--project', name]);
} catch (e) {
if (e instanceof Error && e.message.includes('does not exist')) {
console.error(`Unknown project "${name}"; check angular.json projects key.`);
} else throw e;
} Prevention
- Verify the project key with `ng config projects` or by opening angular.json before passing --project.
- Run ng commands from the directory containing angular.json so the right workspace loads.
- In monorepos, script project name completion (list from angular.json) to avoid typos.
When it happens
Trigger: Calling `ng generate module|pipe` with --project=<name> (or having a default project) where <name> is not a key under "projects" in angular.json/workspace config.
Common situations: Typo in the project name, running the schematic in a repo whose angular.json was renamed/removed, working in a subfolder of an Nx/monorepo where the CLI cannot find the workspace, or referencing a library deleted from angular.json.
Related errors
- Option "project" is required.
- Project is not defined in this workspace.
- Targets are not defined for this project.
- Project "${project}" does not exist.
- Project target does not exist.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/6271123dccb1b30c.
Report an issue: GitHub.