angular/angular-cli · error · SchematicsException

Project target "build" not found.

Error message

Project target "build" not found.

What it means

The service-worker schematic (ngsw) requires the target project to have a 'build' target because it reads build options (output path, entry point) from it. When project.targets.get('build') returns undefined it throws targetBuildNotFoundError() with the message `Project target "build" not found.`

Source

Thrown at packages/schematics/angular/service-worker/index.ts:115

    );
  };
}

function getTsSourceFile(host: Tree, path: string): ts.SourceFile {
  const content = host.readText(path);
  const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);

  return source;
}

const serviceWorkerSchematic: RuleFactory<ServiceWorkerOptions> = createProjectSchematic(
  async (options, { project, workspace, tree, context: { logger } }) => {
    if (project.extensions.projectType !== 'application') {
      throw new SchematicsException(`Service worker requires a project type of "application".`);
    }
    const buildTarget = project.targets.get('build');
    if (!buildTarget) {
      throw targetBuildNotFoundError();
    }

    const buildOptions = buildTarget.options as Record<string, string | boolean>;
    const browserEntryPoint = await getMainFilePath(tree, options.project);
    const ngswConfigPath = join(project.root, 'ngsw-config.json');

    if (
      buildTarget.builder === Builders.Application ||
      buildTarget.builder === Builders.BuildApplication
    ) {
      const productionConf = buildTarget.configurations?.production;
      if (productionConf) {
        productionConf.serviceWorker = ngswConfigPath;
      } else {
        logger.warn(
          'No "production" configuration found for build target. ' +
            `The "serviceWorker" option with a value of "${ngswConfigPath}" will need to be set manually.`,
        );

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run the schematic against an application project with a 'build' target: `ng add @angular/pwa --project <app>`.
  2. Add a standard 'build' target under the project's architect section in angular.json first.
  3. Verify the correct default project via `ng config defaultProject` (or projects list) and pass --project explicitly.
  4. Ensure projectType is "application" — libraries also fail the schematic earlier.

Example fix

// angular.json before
"architect": { "my-custom-build": { "builder": "@angular/build:application", ... } }
// after
"architect": { "build": { "builder": "@angular/build:application", ... } }
Defensive patterns

Strategy: validation

Validate before calling

const project = workspace.projects.get(options.project);
if (!project?.targets.get('build')) {
  throw new Error(`ng add @angular/pwa requires project ${options.project} to have a build target`);
}

Try / catch

try {
  await externalSchematic('@schematics/angular', 'service-worker', options);
} catch (err) {
  if (!(err instanceof SchematicsException && err.message.includes('Project target "build" not found'))) throw err;
  // fix angular.json then rerun
}

Prevention

When it happens

Trigger: Running `ng add @angular/pwa` or `ng generate @schematics/angular:service-worker` on a project without an architect 'build' target in angular.json — e.g. a library, or an app built with a custom/renamed target.

Common situations: Adding a PWA to a library project; angular.json where the build target was renamed (e.g. to 'build:prod' as a separate configuration) or removed; monorepos where the CLI resolved to the wrong project.

Related errors


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