angular/angular-cli · error · Error
Build target is not defined for this project.
Error message
Build target is not defined for this project.
What it means
When adding a web worker, the schematic wires a webWorkerTsConfig option into the project's "build" target. If the project has no "build" target defined, this Error is thrown since the tsconfig cannot be attached anywhere meaningful.
Solutions
- Add a "build" target to the project in angular.json configured with @angular/build:application (or build-angular:application/browser).
- Ensure the target is named "build" — if you renamed it (e.g. to "compile"), rename it back or add an alias target.
- After the build target exists, rerun `ng g web-worker <name> --project=<project>` so the worker tsconfig gets wired in.
Example fix
// before (angular.json project)
"architect": { "test": { ... } }
// after
"architect": { "build": { "builder": "@angular/build:application", "options": { ... } }, "test": { ... } } Defensive patterns
Strategy: validation
Validate before calling
const ws = JSON.parse(fs.readFileSync('angular.json', 'utf8'));
const p = ws.projects?.[name];
if (!p?.architect?.build && !p?.targets?.build) {
throw new Error(`Project "${name}" has no "build" target; add @angular/build:application first.`);
} Try / catch
try {
await ngGenerate(['web-worker', workerName, '--project', name]);
} catch (e) {
if (String((e as Error).message).includes('Build target is not defined')) {
console.error(`Add a "build" target for "${name}" in angular.json, then retry.`);
} else throw e;
} Prevention
- Keep the standard "build" target name in every project's architect section.
- Avoid renaming the build target when customizing angular.json.
- Scaffold projects with the standard Angular builder set so schematics can find their targets.
When it happens
Trigger: Running `ng generate web-worker` on a project (after the project lookup succeeds) whose angular.json targets/architect section lacks a "build" target — e.g. custom projects, test-only projects, or heavily restructured workspaces.
Common situations: Projects assembled manually without the standard application builder targets, monorepo setups where the build target was renamed, or projects migrated where the architect section was trimmed.
Related errors
- Cannot find 'options' for
- Could not find (/.angular.json)
- Invalid project name
- outputPath for target is not a string.
- Project name " " doesn't not exist.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/76278ffb599fe175.
Report an issue: GitHub.
Appendix: source
Thrown at packages/schematics/angular/web-worker/index.ts:113
const root = project.root || '';
const templateSourceWorkerConfig = apply(url('./files/worker-tsconfig'), [
applyTemplates({
...options,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(root),
}),
move(root),
]);
return chain([
// Add project configuration.
updateWorkspace((workspace) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const project = workspace.projects.get(options.project)!;
const buildTarget = project.targets.get('build');
const testTarget = project.targets.get('test');
if (!buildTarget) {
throw new Error(`Build target is not defined for this project.`);
}
const workerConfigPath = join(root, 'tsconfig.worker.json');
(buildTarget.options ??= {}).webWorkerTsConfig ??= workerConfigPath;
if (testTarget) {
(testTarget.options ??= {}).webWorkerTsConfig ??= workerConfigPath;
}
}),
// Create the worker in a sibling module.
options.snippet ? addSnippet(options) : noop(),
// Add the worker.
mergeWith(templateSourceWorkerCode),
mergeWith(templateSourceWorkerConfig),
]);
},
);
export default webWorkerSchematic;View on GitHub (pinned to bb72145f9a)