angular/angular-cli · error · FileDoesNotExistException

Path "${path}" does not exist.

Error message

Path "${path}" does not exist.

What it means

NullTree is a no-op tree used by schematics (e.g. for blank/empty rules); it intentionally has no files, so readText(path) always throws FileDoesNotExistException for every path. Reading any file from a NullTree can never succeed.

Source

Thrown at packages/angular_devkit/schematics/src/tree/null.ts:78

    this[TreeSymbol] = () => this;
  }

  branch(): Tree {
    return new NullTree();
  }
  merge(_other: Tree, _strategy?: MergeStrategy): void {}

  readonly root: DirEntry = new NullTreeDirEntry(normalize('/'));

  // Simple readonly file system operations.
  exists(_path: string) {
    return false;
  }
  read(_path: string) {
    return null;
  }
  readText(path: string): string {
    throw new FileDoesNotExistException(path);
  }
  readJson(path: string): JsonValue {
    throw new FileDoesNotExistException(path);
  }
  get(_path: string) {
    return null;
  }
  getDir(path: string): NullTreeDirEntry {
    return new NullTreeDirEntry(normalize('/' + path));
  }
  visit(): void {}

  // Change content of host files.
  beginUpdate(path: string): never {
    throw new FileDoesNotExistException(path);
  }
  commitUpdate(record: UpdateRecorder): never {
    throw new FileDoesNotExistException(

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Populate the test tree with files before reading: use SchematicTestRunner and writeFile/app.caller, or run against a real sample app.
  2. Guard with tree.exists(path) and skip or create the file when the tree is empty.
  3. Verify the rule receives the intended Tree — don't construct NullTree outside tests; use HostTree/branch for in-memory manipulation.

Example fix

// before
const text = tree.readText('/src/app/app.component.ts');
// after
if (!tree.exists('/src/app/app.component.ts')) {
  return; // NullTree/empty test tree — nothing to do
}
const text = tree.readText('/src/app/app.component.ts');
Defensive patterns

Strategy: validation

Validate before calling

if (!tree.exists(path)) {
  return; // NullTree or empty test tree
}

Try / catch

try {
  const text = tree.readText(path);
} catch (e) {
  if ((e as any).constructor?.name === 'FileDoesNotExistException') {
    return; // NullTree has no files
  } else throw e;
}

Prevention

When it happens

Trigger: Running a rule against a NullTree — commonly in unit tests using SchematicTestRunner with an empty/null collection, or code invoked with the tree from a 'blank' schematic — and calling tree.readText on any path.

Common situations: Testing a schematic without first writing template files into the test tree; a schematic that assumes a real project tree but is executed in a context that supplies NullTree; accidentally importing/using NullTree in production code paths.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/74c035ee10eac8e4. Report an issue: GitHub.