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

  1. Pass the project explicitly: 'ng build my-app'
  2. Change the working directory into the specific project folder that has its own angular.json
  3. Use a defaultProject/configured project in angular.json or an npm script per project
  4. 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

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


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/a081fc35d8cf5f28. Report an issue: GitHub.