angular/angular-cli · error · Error
The builder requires a target.
Error message
The builder requires a target.
What it means
generateBrowserWebpackConfigFromContext needs the architect target (project name) to load project metadata and resolve the project root. When context.target is null — i.e. the builder was invoked outside the normal architect target execution flow — it throws 'The builder requires a target.'. It is an invocation-context validation error, not a code or config content problem.
Source
Thrown at packages/angular_devkit/build_angular/src/utils/webpack-browser-config.ts:139
hash.update('$localize' + i18nHash);
},
);
});
},
});
}
return { ...result, i18n };
}
export async function generateBrowserWebpackConfigFromContext(
options: BrowserBuilderSchema,
context: BuilderContext,
webpackPartialGenerator: WebpackPartialGenerator,
extraBuildOptions: Partial<NormalizedBrowserBuilderSchema> = {},
): Promise<{ config: Configuration; projectRoot: string; projectSourceRoot?: string }> {
const projectName = context.target && context.target.project;
if (!projectName) {
throw new Error('The builder requires a target.');
}
const workspaceRoot = context.workspaceRoot;
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? '');
const sourceRoot = projectMetadata.sourceRoot as string | undefined;
const projectSourceRoot = sourceRoot ? path.join(workspaceRoot, sourceRoot) : undefined;
const normalizedOptions = normalizeBrowserSchema(
workspaceRoot,
projectRoot,
projectSourceRoot,
options,
projectMetadata,
context.logger,
);
const config = await generateWebpackConfig(View on GitHub (pinned to bb72145f9a)
Solutions
- Schedule the builder through architect.scheduleTarget({ project, target | configuration }) with an explicit project name
- If invoking programmatically, set context.target = { project: '<project>', target: '<target>', builder: '<builder:target>' } on your context
- Verify the target's project exists in angular.json and the file parses correctly
Example fix
// before
context.scheduleBuilder('@angular-devkit/build-angular:browser', options);
// after
context.scheduleTarget({ project: 'my-app', target: 'build' }, options); Defensive patterns
Strategy: validation
Validate before calling
// Before scheduling/executing the builder:
if (!context.target || !context.target.project) {
throw new Error('The builder requires a target: schedule via architect.scheduleTarget({ project, target }).');
}
const projectNames = Object.keys(require('./angular.json').projects);
if (!projectNames.includes(context.target.project)) {
throw new Error(`Unknown project ${context.target.project}; known: ${projectNames.join(', ')}`);
} Type guard
function hasArchitectTarget(ctx: { target?: { project?: string } | null }): ctx is { target: { project: string } } {
return typeof ctx.target?.project === 'string' && ctx.target.project.length > 0;
} Try / catch
try {
const { config } = await generateBrowserWebpackConfigFromContext(...);
} catch (e) {
if ((e as Error).message === 'The builder requires a target.') {
throw new Error('Invoke this builder through an architect target (ng build / scheduleTarget), not bare scheduleBuilder.');
}
throw e;
} Prevention
- Always schedule builders with scheduleTarget including an explicit project name
- In test harnesses, populate mock context.target before calling builder logic
- Keep angular.json valid; a missing project entry can null out target resolution
When it happens
Trigger: Calling executeBrowserBuilder (or this builder) programmatically with a context lacking a target; scheduling a builder without specifying project/target in architect.scheduleTarget; a corrupted angular.json entry missing the project the target refers to.
Common situations: Custom scripts invoking builders via the BuilderHost API, test harnesses creating mock BuilderContext objects without setting target, dynamic target composition where project name is lost.
Related errors
- Project "${project}" does not exist.
- Project target does not exist.
- A builder is not set for target '${target}' in project '${pr
- Could not find the '${builderConf}' builder's node package.
- Cannot determine project for command. This is a multi-projec
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/3291588ae4fc1376.
Report an issue: GitHub.