{"record":{"id":"e86cc89ae7e99975","repo":"angular/angular-cli","slug":"targets-are-not-defined-for-this-project","errorCode":null,"errorMessage":"Targets are not defined for this project.","messagePattern":"Targets are not defined for this project\\.","errorType":"validation","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/angular/pwa/pwa/index.ts","lineNumber":88,"sourceCode":"\n    const workspace = await readWorkspace(host);\n\n    if (!options.project) {\n      throw new SchematicsException('Option \"project\" is required.');\n    }\n\n    const project = workspace.projects.get(options.project);\n    if (!project) {\n      throw new SchematicsException(`Project is not defined in this workspace.`);\n    }\n\n    if (project.extensions['projectType'] !== 'application') {\n      throw new SchematicsException(`PWA requires a project type of \"application\".`);\n    }\n\n    // Find all the relevant targets for the project\n    if (project.targets.size === 0) {\n      throw new SchematicsException(`Targets are not defined for this project.`);\n    }\n\n    const buildTargets = [];\n    const testTargets = [];\n    for (const target of project.targets.values()) {\n      if (\n        target.builder === '@angular-devkit/build-angular:browser' ||\n        target.builder === '@angular-devkit/build-angular:application' ||\n        target.builder === '@angular/build:application'\n      ) {\n        buildTargets.push(target);\n      } else if (\n        target.builder === '@angular-devkit/build-angular:karma' ||\n        target.builder === '@angular/build:karma'\n      ) {\n        testTargets.push(target);\n      }\n    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/pwa/pwa/index.ts#L70-L106","documentation":"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.","triggerScenarios":"Project in angular.json exists with projectType 'application' but has an empty or missing 'architect'/'targets' section (no build target).","commonSituations":"Hand-edited angular.json with stripped targets, generated projects whose architect section was removed, custom workspace tooling that omitted targets.","solutions":["Ensure the project has a build target (architect/build section) in angular.json","Regenerate the project scaffolding with ng generate application and re-run the schematic","Restore the removed 'architect' block in angular.json","Run ng build to confirm the project is buildable before adding PWA"],"exampleFix":"// before (angular.json)\n\"my-app\": { \"projectType\": \"application\", \"architect\": {} }\n// after\n\"my-app\": { \"projectType\": \"application\", \"architect\": { \"build\": { \"builder\": \"@angular-devkit/build-angular:application\", ... } } }","handlingStrategy":"validation","validationCode":"const p = angularJson.projects[name];\nif (!p?.architect || Object.keys(p.architect).length === 0) {\n  throw new Error(`${name} has no targets; add a build target first`);\n}","typeGuard":"function hasTargets(p: { targets?: { size?: number }; architect?: Record<string, unknown> }): boolean {\n  return (p.targets ? p.targets.size ?? 0 > 0 : false) || Object.keys(p.architect ?? {}).length > 0;\n}","tryCatchPattern":"try {\n  await runPwaSchematic(projectName);\n} catch (e) {\n  if (String(e.message).includes('Targets are not defined')) {\n    console.error(`Add a build target to \"${projectName}\" in angular.json first`);\n  }\n}","preventionTips":["Never strip the architect/targets section when hand-editing angular.json","Verify ng build works for the project before adding PWA","Use ng generate application rather than hand-authoring project entries"],"tags":["angular","schematics","configuration"],"backgroundTag":"missing-build-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}