angular/angular-cli · error · SchematicsException

Project target "build" not found.

Error message

Project target "build" not found.

What it means

getMainFilePath in packages/schematics/angular/utility/standalone/util.ts resolves a project's main file via its 'build' target options. If the project or its 'build' target does not exist it throws targetBuildNotFoundError(), producing `Project target "build" not found.` It is shared by the browser-entry-point and main-file-path logic of several schematics.

Source

Thrown at packages/schematics/angular/utility/standalone/util.ts:28

import { join } from 'node:path/posix';
import ts from 'typescript';
import { Change, applyToUpdateRecorder } from '../change';
import { targetBuildNotFoundError } from '../project-targets';
import { getWorkspace } from '../workspace';
import { Builders } from '../workspace-models';

/**
 * Finds the main file of a project.
 * @param tree File tree for the project.
 * @param projectName Name of the project in which to search.
 */
export async function getMainFilePath(tree: Tree, projectName: string): Promise<string> {
  const workspace = await getWorkspace(tree);
  const project = workspace.projects.get(projectName);
  const buildTarget = project?.targets.get('build');

  if (!project || !buildTarget) {
    throw targetBuildNotFoundError();
  }

  const options = buildTarget.options as Record<string, string>;

  if (
    buildTarget.builder === Builders.Application ||
    buildTarget.builder === Builders.BuildApplication
  ) {
    // These builders support a default of `<project_source_root>/main.ts`
    const projectSourceRoot = project.sourceRoot ?? join(project.root, 'src');

    return options.browser ?? join(projectSourceRoot, 'main.ts');
  }

  return options.main;
}

/**

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Ensure the project has a standard 'build' target (builder @angular-devkit/build-angular:browser or @angular/build:application) in angular.json.
  2. Pass the correct application project name via --project.
  3. If using a custom builder setup, add an alias 'build' target pointing at your build configuration.
  4. Verify the project name exists with `ng config projects` / the projects section of angular.json.

Example fix

// before
"architect": { "compile": { "builder": "@angular-devkit/build-angular:browser", ... } }
// after
"architect": { "build": { "builder": "@angular-devkit/build-angular:browser", ... } }
Defensive patterns

Strategy: validation

Validate before calling

const project = workspace.projects.get(projectName);
if (!project?.targets.get('build')) {
  throw new Error(`Project ${projectName} has no build target; getMainFilePath will fail`);
}

Type guard

function canResolveMainFilePath(p?: { targets: { get(name: string): { builder: string } | null } | null }): boolean {
  return !!p?.targets.get('build');
}

Try / catch

try {
  const main = await getMainFilePath(tree, projectName);
} catch (err) {
  if (!(err instanceof SchematicsException && err.message.includes('Project target "build" not found'))) throw err;
  // fall back to manually configured main path or fix angular.json
}

Prevention

When it happens

Trigger: Any schematic that calls getMainFilePath (standalone migration, service-worker, app-shell, SSR flows) against a project lacking a 'build' target in angular.json, or with a project name that doesn't exist in the workspace.

Common situations: Custom build pipelines without an architect 'build' target; Bazel or Nrwl/Nx setups where targets live under different names; typo'd --project name; pre-v17 workspaces using 'browser' or 'deployment' targets only with the build target deleted.

Related errors


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