angular/angular-cli · error · FileDoesNotExistException
Path "${path}" does not exist.
Error message
Path "${path}" does not exist. What it means
FileDoesNotExistException from HostTree.readText: read(path) returned null, meaning the file does not exist in the tree, and readText (which must return a string, not null) throws instead. This is the strict, typed counterpart to read(), which tolerates missing files by returning null.
Source
Thrown at packages/angular_devkit/schematics/src/tree/host-tree.ts:301
}
});
}
get root(): DirEntry {
return this.getDir('/');
}
// Readonly.
read(path: string): Buffer | null {
const entry = this.get(path);
return entry ? entry.content : null;
}
readText(path: string): string {
const data = this.read(path);
if (data === null) {
throw new FileDoesNotExistException(path);
}
const decoder = new TextDecoder('utf-8', { fatal: true });
try {
// With the `fatal` option enabled, invalid data will throw a TypeError
return decoder.decode(data);
} catch (e) {
// The second part should not be needed. But Jest does not support instanceof correctly.
// See: https://github.com/jestjs/jest/issues/2549
if (
e instanceof TypeError ||
(e as NodeJS.ErrnoException).code === 'ERR_ENCODING_INVALID_ENCODED_DATA'
) {
throw new Error(`Failed to decode "${path}" as UTF-8 text.`, { cause: e });
}
throw e;
}View on GitHub (pinned to bb72145f9a)
Solutions
- Guard with if (!tree.exists(path)) { tree.create(path, defaultContent); } before calling readText.
- Use tree.read(path) which returns Buffer|null and handle null yourself.
- Fix the path — ensure it is absolute (leading '/') and matches the actual project layout.
- Ensure the rule that creates the file executes before the rule that reads it (rule ordering in chain()).
Example fix
// before
const text = tree.readText('/angular.json');
// after
if (!tree.exists('/angular.json')) {
throw new SchematicsException('Not inside an Angular workspace.');
}
const text = tree.readText('/angular.json'); Defensive patterns
Strategy: validation
Validate before calling
if (!tree.exists('/angular.json')) {
throw new SchematicsException('Not inside an Angular workspace.');
} Type guard
function hasText(tree: Tree, path: string): boolean {
return tree.read(path) !== null;
} Try / catch
try { const text = tree.readText(path); } catch (e) { if (e instanceof FileDoesNotExistException) { /* create default or bail with SchematicsException */ } else { throw e; } } Prevention
- Use tree.exists() before readText
- Prefer tree.read() (returns null) when absence is expected
- Ensure path is absolute with a leading '/'
- Order chain() rules so creators run before readers
When it happens
Trigger: Calling tree.readText(path) for a path never created or already deleted; also indirectly via content() and applyChanges() when operating on an absent path.
Common situations: A schematic reads a config/template file that the target project does not have (different Angular version, standalone vs module-based, customized workspace); a prior rule's conditional create didn't run; wrong leading-slash path (relative 'src/...' vs '/src/...').
Related errors
- Path "${path}" does not exist.
- Path "${p}" 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/2719b6e1774dfa15.
Report an issue: GitHub.