angular/angular-cli · error · FileDoesNotExistException
Path "${p}" does not exist.
Error message
Path "${p}" does not exist. What it means
HostTree.overwrite(path, content) only modifies existing files; it never creates them. If the normalized path does not exist in the tree's virtual file system it throws FileDoesNotExistException. Use create() for new files instead.
Source
Thrown at packages/angular_devkit/schematics/src/tree/host-tree.ts:383
}
maybeCache = new HostDirEntry(parent && this.getDir(parent), p, this._recordSync, this);
this._dirCache.set(p, maybeCache);
}
return maybeCache;
}
visit(visitor: FileVisitor): void {
this.root.visit((path, entry) => {
visitor(path, entry);
});
}
// Change content of host files.
overwrite(path: string, content: Buffer | string): void {
const p = this._normalizePath(path);
if (!this._recordSync.exists(p)) {
throw new FileDoesNotExistException(p);
}
const c = typeof content == 'string' ? Buffer.from(content) : content;
this._record.overwrite(p, c as {} as virtualFs.FileBuffer).subscribe();
}
beginUpdate(path: string): UpdateRecorder {
const entry = this.get(path);
if (!entry) {
throw new FileDoesNotExistException(path);
}
return UpdateRecorderBase.createFromFileEntry(entry);
}
commitUpdate(record: UpdateRecorder): void {
if (record instanceof UpdateRecorderBase) {
const path = record.path;
const entry = this.get(path);
if (!entry) {
throw new ContentHasMutatedException(path);View on GitHub (pinned to bb72145f9a)
Solutions
- Guard with tree.exists(path) and call tree.create(path, content) when it's absent.
- Confirm the exact path — check the project layout and Angular CLI version conventions (paths move between versions).
- Insert the file earlier in the pipeline (template/merge schematic) before overwriting.
Example fix
// before
tree.overwrite('/src/app/legacy.service.ts', newContent);
// after
const p = '/src/app/legacy.service.ts';
if (tree.exists(p)) {
tree.overwrite(p, newContent);
} else {
tree.create(p, newContent);
} Defensive patterns
Strategy: validation
Validate before calling
const canOverwrite = tree.exists(path);
Try / catch
try {
tree.overwrite(path, content);
} catch (e) {
if ((e as any).constructor?.name === 'FileDoesNotExistException') {
tree.create(path, content); // or surface a clear message
} else throw e;
} Prevention
- Check tree.exists(path) before overwrite
- Use create() for files the rule introduces itself
- Verify paths against the current Angular CLI version's project layout
- Ensure prior rules/templates that generate the file run before the overwrite step
When it happens
Trigger: Calling tree.overwrite(path, ...) on a path never created in the tree; calling overwrite in a rule that assumed a prior rule/template had generated the file; internally from commitUpdate/merge when the file was deleted between steps.
Common situations: Angular schematic rules editing files (e.g. app.component.ts, angular.json) whose path changed across CLI versions; typos in paths; running a rule on a project where the target file was renamed or removed.
Related errors
- Path "${path}" does not exist.
- Path "${path}" does not exist.
- Path "${path}" does not exist.
- Path "${record instanceof UpdateRecorderBase ? record.path :
- Cannot find "${configFilePath}".
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/c01cb3c4a523aa7d.
Report an issue: GitHub.