angular/angular-cli · error · Error
The builder requires a target.
Error message
The builder requires a target.
What it means
_renderUniversal combines browser and server build results to prerender pages and needs the project name from context.target to resolve project metadata (root, sourceRoot) for file operations. If context.target is missing or lacks a project, it throws 'The builder requires a target.' Same family as errors 153/155/157: programmatic invocation without an architect target.
Source
Thrown at packages/angular_devkit/build_angular/src/builders/prerender/index.ts:161
} finally {
await Promise.all([browserTargetRun.stop(), serverTargetRun.stop()]);
}
}
/**
* Renders each route and writes them to
* <route>/index.html for each output path in the browser result.
*/
async function _renderUniversal(
options: PrerenderBuilderOptions,
context: BuilderContext,
browserResult: BrowserBuilderOutput,
serverResult: ServerBuilderOutput,
browserOptions: BrowserBuilderOptions,
): Promise<PrerenderBuilderOutput> {
const projectName = context.target && context.target.project;
if (!projectName) {
throw new Error('The builder requires a target.');
}
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = path.join(
context.workspaceRoot,
(projectMetadata.root as string | undefined) ?? '',
);
// Users can specify a different base html file e.g. "src/home.html"
const indexFile = getIndexOutputFile(browserOptions.index);
const { styles: normalizedStylesOptimization } = normalizeOptimization(
browserOptions.optimization,
);
let zonePackage: string | undefined;
try {
zonePackage = require.resolve('zone.js/node', { paths: [context.workspaceRoot] });
} catch {}View on GitHub (pinned to bb72145f9a)
Solutions
- Run prerender via `ng run <project>:prerender` so a target is bound.
- Use scheduleTarget({ project, target: 'prerender' }) in programmatic usage.
- If constructing contexts manually, ensure target: { project: '<name>' } is set.
- Define the prerender target in angular.json for the project.
Example fix
// before
await context.scheduleBuilder('@angular-devkit/build-angular:prerender', options);
// after
await context.scheduleTarget({ target: 'prerender', project: 'my-app' }, options); Defensive patterns
Strategy: validation
Validate before calling
if (!context.target?.project) {
throw new Error('prerender requires a target: use ng run <project>:prerender.');
} Try / catch
try {
await prerender(context, options);
} catch (e) {
if (e.message === 'The builder requires a target.') {
console.error('Invoke prerender via ng run with a project target.');
} else throw e;
} Prevention
- Schedule prerender with scheduleTarget, not scheduleBuilder.
- Assert context.target.project before calling prerender internals.
- Keep the prerender target defined in angular.json.
- Centralize builder invocation in a helper that enforces target binding.
When it happens
Trigger: Executing the prerender builder through a custom Architect context without target.project; scheduling via scheduleBuilder instead of scheduleTarget; tooling that calls _renderUniversal/execute directly.
Common situations: Custom prerender scripts; test harnesses invoking the builder directly; workspaces where the builder is driven by external runners that omit target binding.
Related errors
- 'handleSSGRoute' was called for a route which rendering mode
- The 'getPrerenderParams' function defined for the '${stripLe
- Could not find any routes to prerender.
- Rendering failed with ${numErrors} worker errors.
- A module or bootstrap option must be provided.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/363b69a0be61dd46.
Report an issue: GitHub.