{"record":{"id":"de26d3ebb34cd71d","repo":"angular/angular-cli","slug":"project-target-build-not-found-de26d3","errorCode":null,"errorMessage":"Project target \"build\" not found.","messagePattern":"Project target \"build\" not found\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/service-worker/index.ts","lineNumber":115,"sourceCode":"    );\n  };\n}\n\nfunction getTsSourceFile(host: Tree, path: string): ts.SourceFile {\n  const content = host.readText(path);\n  const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);\n\n  return source;\n}\n\nconst serviceWorkerSchematic: RuleFactory<ServiceWorkerOptions> = createProjectSchematic(\n  async (options, { project, workspace, tree, context: { logger } }) => {\n    if (project.extensions.projectType !== 'application') {\n      throw new SchematicsException(`Service worker requires a project type of \"application\".`);\n    }\n    const buildTarget = project.targets.get('build');\n    if (!buildTarget) {\n      throw targetBuildNotFoundError();\n    }\n\n    const buildOptions = buildTarget.options as Record<string, string | boolean>;\n    const browserEntryPoint = await getMainFilePath(tree, options.project);\n    const ngswConfigPath = join(project.root, 'ngsw-config.json');\n\n    if (\n      buildTarget.builder === Builders.Application ||\n      buildTarget.builder === Builders.BuildApplication\n    ) {\n      const productionConf = buildTarget.configurations?.production;\n      if (productionConf) {\n        productionConf.serviceWorker = ngswConfigPath;\n      } else {\n        logger.warn(\n          'No \"production\" configuration found for build target. ' +\n            `The \"serviceWorker\" option with a value of \"${ngswConfigPath}\" will need to be set manually.`,\n        );","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/service-worker/index.ts#L97-L133","documentation":"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.`","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the schematic against an application project with a 'build' target: `ng add @angular/pwa --project <app>`.","Add a standard 'build' target under the project's architect section in angular.json first.","Verify the correct default project via `ng config defaultProject` (or projects list) and pass --project explicitly.","Ensure projectType is \"application\" — libraries also fail the schematic earlier."],"exampleFix":"// angular.json before\n\"architect\": { \"my-custom-build\": { \"builder\": \"@angular/build:application\", ... } }\n// after\n\"architect\": { \"build\": { \"builder\": \"@angular/build:application\", ... } }","handlingStrategy":"validation","validationCode":"const project = workspace.projects.get(options.project);\nif (!project?.targets.get('build')) {\n  throw new Error(`ng add @angular/pwa requires project ${options.project} to have a build target`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await externalSchematic('@schematics/angular', 'service-worker', options);\n} catch (err) {\n  if (!(err instanceof SchematicsException && err.message.includes('Project target \"build\" not found'))) throw err;\n  // fix angular.json then rerun\n}","preventionTips":["Check the project's architect targets include 'build' before ng add @angular/pwa.","Run PWA setup on applications, not libraries.","Avoid renaming the 'build' target in angular.json.","Confirm the default project in angular.json before relying on it."],"tags":["schematics","service-worker","pwa","angular-json","configuration"],"backgroundTag":"missing-build-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}