angular/angular-cli · error · CommandModuleError
Cannot determine project for command. This is a multi-projec
Error message
Cannot determine project for command.
This is a multi-project workspace and more than one project supports this command. Run "ng ${this.command}" to execute the command for a specific project or change the current working directory to a project directory.
Available projects are:
${allProjectsForTargetName
.sort()
.map((p) => `- ${p}`)
.join('\n')} What it means
Commands that operate on an architect target (like ng build/serve/test) need to know which project to run against. In a multi-project workspace where more than one project defines the requested target, the CLI cannot pick one and throws this error listing the candidate projects.
Source
Thrown at packages/angular/cli/src/command-builder/architect-command-module.ts:187
}
if (this.multiTarget) {
// For multi target commands, we always list all projects that have the target.
return allProjectsForTargetName;
} else {
if (allProjectsForTargetName.length === 1) {
return allProjectsForTargetName;
}
const maybeProject = getProjectByCwd(workspace);
if (maybeProject) {
return allProjectsForTargetName.includes(maybeProject) ? [maybeProject] : undefined;
}
const { getYargsCompletions, help } = this.context.args.options;
if (!getYargsCompletions && !help) {
// Only issue the below error when not in help / completion mode.
throw new CommandModuleError(
'Cannot determine project for command.\n' +
'This is a multi-project workspace and more than one project supports this command. ' +
`Run "ng ${this.command}" to execute the command for a specific project or change the current ` +
'working directory to a project directory.\n\n' +
`Available projects are:\n${allProjectsForTargetName
.sort()
.map((p) => `- ${p}`)
.join('\n')}`,
);
}
}
return undefined;
}
/** @returns a sorted list of project names to be used for auto completion. */
private getProjectChoices(): string[] | undefined {
const { workspace } = this.context;View on GitHub (pinned to bb72145f9a)
Solutions
- Pass the project explicitly: 'ng build my-app'
- Change the working directory into the specific project folder that has its own angular.json
- Use a defaultProject/configured project in angular.json or an npm script per project
- In CI, parameterize the project name instead of relying on cwd inference
Example fix
// before ing build // after cd projects/admin && ng build # or: ng build admin
Defensive patterns
Strategy: validation
Validate before calling
import { workspaces } from '@angular-devkit/core';
// or simply:
const count = getProjectsInAngularJson().filter(p => hasTarget(p, 'build')).length;
if (count > 1) {
args.push('--project', process.env.PROJECT ?? count && 'specify-a-project');
} Try / catch
try {
execSync('ng build', { stdio: 'inherit' });
} catch (e) {
if (String(e).includes('Cannot determine project')) {
const projects = String(e).match(/- (.+)/g) ?? [];
throw new Error(`Pass --project; candidates: ${projects.join(', ')}`);
}
throw e;
} Prevention
- Always pass --project in multi-project workspaces and CI
- Run commands from within a single project directory when relying on inference
- Keep one 'defaultProject'/'cli.defaultProjectName' configured
- Script per-app commands (npm run build:admin) instead of bare ng build
When it happens
Trigger: Running e.g. 'ng build' (no project argument) in a workspace with several projects that each have a 'build' target, and the current directory is the workspace root, not inside a specific project.
Common situations: Nx/npm-style monorepos with apps/lib1/lib2; running commands from the repo root in CI scripts; after adding a second app to an angular.json that previously had one.
Related errors
- Project "${project}" does not exist.
- Project target does not exist.
- A builder is not set for target '${target}' in project '${pr
- Could not find ${level} workspace.
- Could not find a ${level} workspace. Are you in a project?
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/a081fc35d8cf5f28.
Report an issue: GitHub.