{"record":{"id":"3e58fe1163abf74a","repo":"angular/angular-cli","slug":"the-builder-requires-a-target-3e58fe","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/utils/i18n-webpack.ts","lineNumber":40,"sourceCode":"import { readTsconfig } from '../utils/read-tsconfig';\n\n/**\n * The base module location used to search for locale specific data.\n */\nconst LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global';\n\n// Re-export for use within Webpack related builders\nexport { I18nOptions, loadTranslations };\n\nexport async function configureI18nBuild<T extends BrowserBuilderSchema | ServerBuilderSchema>(\n  context: BuilderContext,\n  options: T,\n): Promise<{\n  buildOptions: T;\n  i18n: I18nOptions;\n}> {\n  if (!context.target) {\n    throw new Error('The builder requires a target.');\n  }\n\n  const buildOptions = { ...options };\n  const tsConfig = await readTsconfig(buildOptions.tsConfig, context.workspaceRoot);\n  const metadata = await context.getProjectMetadata(context.target);\n  const i18n = createI18nOptions(metadata, buildOptions.localize, context.logger);\n\n  // No additional processing needed if no inlining requested and no source locale defined.\n  if (!i18n.shouldInline && !i18n.hasDefinedSourceLocale) {\n    return { buildOptions, i18n };\n  }\n\n  const projectRoot = path.join(context.workspaceRoot, (metadata.root as string) || '');\n  // The trailing slash is required to signal that the path is a directory and not a file.\n  const projectRequire = createRequire(projectRoot + '/');\n  const localeResolver = (locale: string) =>\n    projectRequire.resolve(path.join(LOCALE_DATA_BASE_MODULE, locale));\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/utils/i18n-webpack.ts#L22-L58","documentation":"configureI18nBuild needs the builder's target (from the Architect scheduler) to read project metadata such as source root and i18n options. When context.target is null — e.g. when the builder is invoked programmatically or via an API without a target — it cannot resolve project configuration and throws.","triggerScenarios":"Invoking a builder through architect schedule with no explicit target, calling the builder API directly (e.g. in tests or a custom tool) without providing target in the BuilderContext, or running from tooling that strips target information.","commonSituations":"Custom scripts calling builder handlers directly; unit tests instantiating the builder context without a target; third-party tooling wrapping the CLI builders programmatically.","solutions":["Invoke the build via `ng build` so a target (project:builder) is always provided.","When scheduling programmatically, pass the target: `context.scheduler.schedule(':@project:builder:configuration', options)` with a named project/builder.","In tests, construct a fake BuilderContext whose `target` is set to a valid Target object.","Refactor to call createI18nOptions directly with project metadata if you don't need target-based resolution."],"exampleFix":"// before (programmatic)\nawait context.scheduler.schedule('ng:build', options);\n// after\nawait context.scheduler.schedule('@angular-devkit/build-angular:browser:production', options);","handlingStrategy":"try-catch","validationCode":"if (!context.target) throw new Error('configureI18nBuild requires context.target; schedule the builder via a named target.');","typeGuard":"function hasTarget(ctx: BuilderContext): ctx is BuilderContext & { target: Target } {\n  return !!ctx.target && typeof ctx.target.project === 'string';\n}","tryCatchPattern":"try {\n  await configureI18nBuild(context, options);\n} catch (err) {\n  if (err.message === 'The builder requires a target.') {\n    console.error('Run via `ng build` or schedule with a fully qualified target (project:builder:configuration).');\n  } else throw err;\n}","preventionTips":["Always invoke builders through the Architect scheduler with a named target.","In tests, stub context.target with a valid Target object.","Avoid calling builder handler functions directly.","Pass project/builder/configuration explicitly in programmatic scheduling."],"tags":["i18n","builder-context","configuration"],"backgroundTag":"missing-builder-target","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}