{"record":{"id":"5c23356ad718a4a0","repo":"angular/angular-cli","slug":"the-builder-requires-a-target-5c2335","errorCode":null,"errorMessage":"The builder requires a target.","messagePattern":"The builder requires a target\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/builders/ng-packagr/index.ts","lineNumber":48,"sourceCode":"  return from(\n    (async () => {\n      // Purge old build disk cache.\n      await purgeStaleBuildCache(context);\n\n      const root = context.workspaceRoot;\n      const workspaceRequire = createRequire(root + '/');\n      const ngPackagePath = workspaceRequire.resolve('ng-packagr');\n      const packager = (await import(ngPackagePath)).ngPackagr();\n\n      packager.forProject(resolve(root, options.project));\n\n      if (options.tsConfig) {\n        packager.withTsConfig(resolve(root, options.tsConfig));\n      }\n\n      const projectName = context.target?.project;\n      if (!projectName) {\n        throw new Error('The builder requires a target.');\n      }\n\n      const metadata = await context.getProjectMetadata(projectName);\n      const { enabled: cacheEnabled, path: cacheDirectory } = normalizeCacheOptions(\n        metadata,\n        context.workspaceRoot,\n      );\n\n      const ngPackagrOptions: NgPackagrOptions = {\n        cacheEnabled,\n        poll: options.poll,\n        cacheDirectory: join(cacheDirectory, 'ng-packagr'),\n      };\n\n      return { packager, ngPackagrOptions };\n    })(),\n  ).pipe(\n    switchMap(({ packager, ngPackagrOptions }) =>","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/builders/ng-packagr/index.ts#L30-L66","documentation":"The ng-packagr builder's execute needs the project name from context.target to load project metadata (used for cache options, root, tsConfig resolution, etc.). If no target is present, it throws 'The builder requires a target.' This occurs when the packagr builder is invoked programmatically without an architect target rather than via `ng build <lib>`.","triggerScenarios":"Scheduling the ng-packagr builder via scheduleBuilder or a hand-rolled Architect context without target.project; invoking ng-packagr's execute directly in tests or tooling.","commonSituations":"CI scripts building libraries programmatically; wrapper tools around ng-packagr; custom runners that construct build actions without a target descriptor.","solutions":["Build libraries via `ng build <project>` or `ng run <project>:build` so a target is bound to the context.","When scheduling programmatically, use scheduleTarget({ project, target }) instead of scheduleBuilder.","Provide target.project if you construct the builder context manually.","Define the library's build target in angular.json if missing."],"exampleFix":"// before\nawait context.scheduleBuilder('@angular-devkit/build-angular:ng-packagr', options);\n// after\nawait context.scheduleTarget({ target: 'build', project: 'my-lib' }, options);","handlingStrategy":"validation","validationCode":"if (!context.target?.project) {\n  throw new Error('ng-packagr requires a target: use ng build <lib> or scheduleTarget.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ngBuildLibrary();\n} catch (e) {\n  if (e.message === 'The builder requires a target.') {\n    console.error('Schedule via ng run <project>:build.');\n  } else throw e;\n}","preventionTips":["Build libraries with ng run <project>:build, not scheduleBuilder.","Bind target.project in custom Architect contexts.","Ensure each library has a build target in angular.json.","Wrap programmatic builds in a target-presence assertion."],"tags":["ng-packagr","angular","missing-target","config"],"backgroundTag":"missing-builder-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}