angular/components · error · SchematicsException

Cannot determine project target configuration for: ${buildTa

Error message

Cannot determine project target configuration for: ${buildTarget}.

What it means

getProjectTargetOptions in src/cdk/schematics/utils/project-targets.ts fetches the options record of a named target (e.g. "build", "test", or "serve") from the project definition. If the target does not exist on the project or exists with no options, the schematic cannot read required configuration and throws this SchematicsException naming the missing buildTarget.

Source

Thrown at src/cdk/schematics/utils/project-targets.ts:32

const PROJECT_BUILDERS = new Set([
  '@angular-devkit/build-angular:browser-esbuild',
  '@angular-devkit/build-angular:application',
  '@angular-devkit/build-angular:browser',
  '@angular/build:application',
]);

/** Possible name of CLI builders used to run tests in the project. */
const TEST_BUILDERS = new Set(['@angular-devkit/build-angular:karma', '@angular/build:karma']);

/** Resolves the architect options for the build target of the given project. */
export function getProjectTargetOptions(
  project: ProjectDefinition,
  buildTarget: string,
): Record<string, JsonValue | undefined> {
  const options = project.targets?.get(buildTarget)?.options;

  if (!options) {
    throw new SchematicsException(
      `Cannot determine project target configuration for: ${buildTarget}.`,
    );
  }

  return options;
}

/** Gets all of the default CLI-provided build targets in a project. */
export function getProjectBuildTargets(project: ProjectDefinition): TargetDefinition[] {
  return getTargetsByBuilderName(project, builder => !!builder && PROJECT_BUILDERS.has(builder));
}

/** Gets all of the default CLI-provided testing targets in a project. */
export function getProjectTestTargets(project: ProjectDefinition): TargetDefinition[] {
  return getTargetsByBuilderName(project, builder => !!builder && TEST_BUILDERS.has(builder));
}

/** Gets all targets from the given project that pass a predicate check. */

View on GitHub (pinned to 0411926e7d)

Solutions

  1. Ensure the project defines the expected target (usually "build") under projects.<name>.architect (or "targets") in angular.json.
  2. Add an "options" object to that target — even minimal — so getProjectTargetOptions returns a record instead of undefined.
  3. Run the schematic on an application project that has standard architect targets generated by the CLI.
  4. If targets are defined only per-configuration, move the required keys (main, styles, index) into the base "options" block.

Example fix

// before (angular.json)
"architect": {}
// after (angular.json)
"architect": { "build": { "builder": "@angular-devkit/build-angular:application", "options": { "main": "src/main.ts" } } }
Defensive patterns

Strategy: validation

Validate before calling

const p = JSON.parse(fs.readFileSync('angular.json', 'utf8')).projects[name];
for (const t of ['build', 'test']) {
  if (!p?.architect?.[t]?.options) {
    console.warn(`Project "${name}" is missing architect target "${t}" with base options; schematics may fail.`);
  }
}

Type guard

function hasTargetOptions(p: any, target: string): p is { architect: Record<string, { options: Record<string, unknown> }> } {
  return !!p?.architect?.[target]?.options;
}

Try / catch

try {
  await runSchematic('styles', { project: name });
} catch (e) {
  if (String(e.message).includes('Cannot determine project target configuration')) {
    console.error(`Target missing on "${name}"; add a build target with options in angular.json.`);
  } else throw e;
}

Prevention

When it happens

Trigger: Schematics that read target options — e.g. resolving styles (expectProjectStyleFile), buildOptions for the main file, or inline styles — when the requested target is absent: custom target names, renamed architect targets, library projects without a build target, or angular.json where the target defines only configurations and no base options.

Common situations: Nx or Bazel workspaces with non-standard target naming; users who deleted the "test" or "build" architect section; schematics run with a custom --configuration assumption; projects created outside Angular CLI.

Related errors


AI-assisted analysis of angular/components@0411926e7d (2026-08-31). Data as JSON: /api/errors/a12c81471a5f4733. Report an issue: GitHub.