angular/angular-cli · error · CommandModuleError

Cannot determine project or target.

Error message

Cannot determine project or target.

What it means

The run command's run() method throws this when makeTargetSpecifier returns undefined, meaning the provided options could not be resolved into a project:target target specifier. Neither a direct --target/--project combination nor positional args produced a runnable target.

Source

Thrown at packages/angular/cli/src/commands/run/cli.ts:81

      }, true)
      .strict();

    const target = this.makeTargetSpecifier();
    if (!target) {
      return localYargs;
    }

    const schemaOptions = await this.getArchitectTargetOptions(target);

    return this.addSchemaOptionsToCommand(localYargs, schemaOptions);
  }

  async run(options: Options<RunCommandArgs> & OtherOptions): Promise<number> {
    const target = this.makeTargetSpecifier(options);
    const { target: _target, ...extraOptions } = options;

    if (!target) {
      throw new CommandModuleError('Cannot determine project or target.');
    }

    return this.runSingleTarget(target, extraOptions);
  }

  protected makeTargetSpecifier(options?: Options<RunCommandArgs>): Target | undefined {
    const architectTarget = options?.target ?? this.context.args.positional[1];
    if (!architectTarget) {
      return undefined;
    }

    const [project = '', target = '', configuration] = architectTarget.split(':');

    return {
      project,
      target,
      configuration,
    };

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Provide an explicit target: `ng run my-project:build` or `ng build my-project`.
  2. Check angular.json contains the referenced project/target.
  3. Set "defaultProject" in angular.json or run from inside a project directory.

Example fix

// before
ng run
// after
ng run my-app:serve:development
Defensive patterns

Strategy: validation

Validate before calling

const ng = require('./angular.json');
const hasTarget = options.target || (options.project && ng.projects[options.project]);
if (!hasTarget) {
  throw new Error('Provide an explicit project:target, e.g. ng run my-app:build');
}

Type guard

function canResolveTarget(o: { target?: string; project?: string }): boolean {
  return typeof o.target === 'string' || typeof o.project === 'string';
}

Prevention

When it happens

Trigger: Running `ng run` (or `ng <builder>`) with no positional 'project:target' argument and no project/target options; running `ng <architect command>` in a context where no project and no default target can be resolved.

Common situations: `ng run` with no arguments; running an architect command outside a project directory in a multi-project repo; missing defaultProject in angular.json; typo making the positional arg unparseable.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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