angular/angular-cli · error · SchematicsException

Targets are not defined for this project.

Error message

Targets are not defined for this project.

What it means

The schematic requires the target project to have at least one target configured (build, test, etc.). If project.targets is empty, it cannot find build/test targets to update for PWA service-worker configuration, so it throws.

Source

Thrown at packages/angular/pwa/pwa/index.ts:88

    const workspace = await readWorkspace(host);

    if (!options.project) {
      throw new SchematicsException('Option "project" is required.');
    }

    const project = workspace.projects.get(options.project);
    if (!project) {
      throw new SchematicsException(`Project is not defined in this workspace.`);
    }

    if (project.extensions['projectType'] !== 'application') {
      throw new SchematicsException(`PWA requires a project type of "application".`);
    }

    // Find all the relevant targets for the project
    if (project.targets.size === 0) {
      throw new SchematicsException(`Targets are not defined for this project.`);
    }

    const buildTargets = [];
    const testTargets = [];
    for (const target of project.targets.values()) {
      if (
        target.builder === '@angular-devkit/build-angular:browser' ||
        target.builder === '@angular-devkit/build-angular:application' ||
        target.builder === '@angular/build:application'
      ) {
        buildTargets.push(target);
      } else if (
        target.builder === '@angular-devkit/build-angular:karma' ||
        target.builder === '@angular/build:karma'
      ) {
        testTargets.push(target);
      }
    }

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Ensure the project has a build target (architect/build section) in angular.json
  2. Regenerate the project scaffolding with ng generate application and re-run the schematic
  3. Restore the removed 'architect' block in angular.json
  4. Run ng build to confirm the project is buildable before adding PWA

Example fix

// before (angular.json)
"my-app": { "projectType": "application", "architect": {} }
// after
"my-app": { "projectType": "application", "architect": { "build": { "builder": "@angular-devkit/build-angular:application", ... } } }
Defensive patterns

Strategy: validation

Validate before calling

const p = angularJson.projects[name];
if (!p?.architect || Object.keys(p.architect).length === 0) {
  throw new Error(`${name} has no targets; add a build target first`);
}

Type guard

function hasTargets(p: { targets?: { size?: number }; architect?: Record<string, unknown> }): boolean {
  return (p.targets ? p.targets.size ?? 0 > 0 : false) || Object.keys(p.architect ?? {}).length > 0;
}

Try / catch

try {
  await runPwaSchematic(projectName);
} catch (e) {
  if (String(e.message).includes('Targets are not defined')) {
    console.error(`Add a build target to "${projectName}" in angular.json first`);
  }
}

Prevention

When it happens

Trigger: Project in angular.json exists with projectType 'application' but has an empty or missing 'architect'/'targets' section (no build target).

Common situations: Hand-edited angular.json with stripped targets, generated projects whose architect section was removed, custom workspace tooling that omitted targets.

Related errors


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