angular/angular-cli · error · FileDoesNotExistException

File does not exist.

Error message

File does not exist.

What it means

_read looks up the path in the host's cache; if no entry exists at all, it throws FileDoesNotExistException. The memory host only serves content it has previously stored, so reading a path that was never written (or was deleted) is an immediate failure. It is thrown before the directory/content checks because the entry is absent.

Source

Thrown at packages/angular_devkit/core/src/virtual-fs/host/memory.ts:186

      if (maybeStats) {
        if (maybeStats.isFile()) {
          throw new PathIsFileException(curr);
        }
      } else {
        this._cache.set(curr, this._newDirStats());
      }
    }

    // Create the stats.
    const stats: Stats<SimpleMemoryHostStats> = this._newFileStats(content, old);
    this._cache.set(path, stats);
    this._updateWatchers(path, old ? HostWatchEventType.Changed : HostWatchEventType.Created);
  }
  protected _read(path: Path): FileBuffer {
    path = this._toAbsolute(path);
    const maybeStats = this._cache.get(path);
    if (!maybeStats) {
      throw new FileDoesNotExistException(path);
    } else if (maybeStats.isDirectory()) {
      throw new PathIsDirectoryException(path);
    } else if (!maybeStats.content) {
      throw new PathIsDirectoryException(path);
    } else {
      return maybeStats.content;
    }
  }
  protected _delete(path: Path): void {
    path = this._toAbsolute(path);
    if (this._isDirectory(path)) {
      for (const [cachePath] of this._cache.entries()) {
        if (cachePath.startsWith(path + NormalizedSep) || cachePath === path) {
          this._cache.delete(cachePath);
        }
      }
    } else {
      this._cache.delete(path);

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Verify the exact path exists first via host.exists(path) and log it if missing.
  2. Create the file with host.write(path, content) before attempting to read it.
  3. Fix typos and match path casing exactly to how the file was created.
  4. If the file was deleted or renamed, update the code to read from the new path or restore the content first.

Example fix

// before
const content = host.read(normalize('src/config.json')); // may throw
// after
const p = normalize('src/config.json');
if (host.exists(p)) {
  const content = host.read(p);
} else {
  host.write(p, Buffer.from('{}'));
}
Defensive patterns

Strategy: validation

Validate before calling

import { normalize, Path } from '@angular-devkit/core';

function safeRead(host: { exists(p: Path): boolean; read(p: Path): Buffer }, p: Path): Buffer | null {
  const abs = normalize(p);
  return host.exists(abs) ? host.read(abs) : null;
}

Try / catch

import { FileDoesNotExistException } from '@angular-devkit/core';

try {
  const content = host.read(path);
} catch (e) {
  if (e instanceof FileDoesNotExistException) {
    console.warn(`File not found in virtual FS: ${e.path}; creating default`);
    host.write(path, Buffer.from(''));
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling host.content(path) or read() for a path never created via write(); reading after host.delete(path) removed the entry; typos or case-sensitivity mismatches (the memory host uses normalized absolute paths, so 'Src/A.txt' !== 'src/a.txt'); relative paths that do not resolve to the cached absolute path.

Common situations: Schematics reading a template file at a slightly wrong path; forgetting to create the file earlier in the same in-memory tree (unlike a real FS, nothing pre-exists); reading files after a rename moved them; case-sensitivity differences between the developer's OS and the normalized virtual paths.

Related errors


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