angular/angular-cli · error · SchematicsException
Apply not implemented on host trees.
Error message
Apply not implemented on host trees.
What it means
HostTree.apply(action, strategy) is intentionally unimplemented: action-list application is only supported on branching/managed trees (e.g. BranchTree/DelegateTree or the workflow's task pipeline), not on a HostTree backed directly by a filesystem host. Any call throws SchematicsException with this message.
Source
Thrown at packages/angular_devkit/schematics/src/tree/host-tree.ts:426
} else {
throw new InvalidUpdateRecordException();
}
}
// Structural methods.
create(path: string, content: Buffer | string): void {
const c = typeof content == 'string' ? Buffer.from(content) : content;
this._record.create(this._normalizePath(path), c as {} as virtualFs.FileBuffer).subscribe();
}
delete(path: string): void {
this._recordSync.delete(this._normalizePath(path));
}
rename(from: string, to: string): void {
this._recordSync.rename(this._normalizePath(from), this._normalizePath(to));
}
apply(action: Action, strategy?: MergeStrategy): void {
throw new SchematicsException('Apply not implemented on host trees.');
}
private *generateActions(): Iterable<Action> {
for (const record of this._record.records()) {
switch (record.kind) {
case 'create':
yield {
id: this._id,
parent: 0,
kind: 'c',
path: record.path,
content: Buffer.from(record.content),
} as CreateFileAction;
break;
case 'overwrite':
yield {
id: this._id,
parent: 0,View on GitHub (pinned to bb72145f9a)
Solutions
- Remove the apply call — perform the change directly with create/overwrite/delete/rename on the tree instead.
- Use a branching tree (tree.branch()) or the Schematic workflow's commit/task mechanisms if you need action-style batching.
- Route actions through the engine's Tree (from the rule's context), which supports apply semantics, rather than a raw HostTree.
Example fix
// before
tree.apply(action, MergeStrategy.Default);
// after
if (action.kind === 'c') {
tree.create(action.path, action.content);
} else if (action.kind === 'o') {
tree.overwrite(action.path, action.content);
} Defensive patterns
Strategy: fallback
Try / catch
try {
(tree as any).apply(action, strategy);
} catch (e) {
if ((e as Error).message.includes('Apply not implemented')) {
// translate the action to create/overwrite/delete/rename calls instead
} else throw e;
} Prevention
- Never call apply on HostTree; apply changes via create/overwrite/delete/rename
- Use branch trees or the schematic workflow for action batching needs
- Get the Tree from the rule context rather than constructing HostTree for action flows
- Wrap raw action application in a helper that maps action kinds to direct tree ops
When it happens
Trigger: Calling tree.apply(someAction) on a HostTree instance — e.g. via tree.newContent()/action flows that route to apply, or copying code that used Tree.apply on a different tree type.
Common situations: Custom schematics trying to replay recorded actions manually; code ported from older APIs or internal tooling that applied actions to the host tree; tests constructing HostTree directly and exercising action APIs.
Related errors
- schematicName cannot be undefined.
- The "not" keyword is not supported in JSON Schema.
- Could not find (/.angular.json)
- Unknown schematics built-in module '${id}' requested from sc
- A collection and schematic is required during execution.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/ce6499fdaa4dfa43.
Report an issue: GitHub.