facebook/docusaurus · error

Failed to retrieve git history for "${file}" because the fil

Error message

Failed to retrieve git history for "${file}" because the file does not exist.

What it means

Thrown by getFileCommitDate() when the file passed in does not exist on disk (fs.pathExists returns false). This guard runs after the git-installed check and before the git log invocation, ensuring the subprocess is never asked about a non-existent path. Unlike the GitNotFoundError case, this is a plain Error (not recoverable as 'untracked').

Source

Thrown at packages/docusaurus-utils/src/vcs/gitUtils.ts:137

    age = 'oldest',
    includeAuthor = false,
  }: {
    age?: 'oldest' | 'newest';
    includeAuthor?: boolean;
  },
): Promise<{
  date: Date;
  timestamp: number;
  author?: string;
}> {
  if (!hasGit()) {
    throw new GitNotFoundError(
      `Failed to retrieve git history for "${file}" because git is not installed.`,
    );
  }

  if (!(await fs.pathExists(file))) {
    throw new Error(
      `Failed to retrieve git history for "${file}" because the file does not exist.`,
    );
  }

  // We add a "RESULT:" prefix to make parsing easier
  // See why: https://github.com/facebook/docusaurus/pull/10022
  const resultFormat = includeAuthor ? 'RESULT:%ct,%an' : 'RESULT:%ct';

  const result = (await GitCommandQueue.add(() => {
    return execa(
      'git',
      [
        // Do not include GPG signature in the log output
        // See https://github.com/facebook/docusaurus/pull/10022
        '-c',
        'log.showSignature=false',
        'log',
        `--format=${resultFormat}`,

View on GitHub (pinned to 3f483e80e3)

Solutions

  1. Confirm the file at the path printed in the error actually exists (ls / cat the exact path).
  2. If the file was deleted intentionally, refresh whatever produced the file list so it no longer references the removed file.
  3. On Windows, ensure consistent path separators and casing.
  4. If calling getFileCommitDate directly, guard with fs.pathExists yourself and skip non-existent files rather than relying on the throw.

Example fix

// before — caller assumes the file still exists
const info = await getFileCommitDate(filePath, { age: 'newest' });

// after — guard existence
if (!(await fs.pathExists(filePath))) return null;
const info = await getFileCommitDate(filePath, { age: 'newest' });
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'fs-extra';

if (!(await fs.pathExists(file))) {
  throw new Error(`Cannot get git history: file does not exist: ${file}`);
}
await getFileCommitDate(file, { age: 'newest' });

Try / catch

try {
  await getFileCommitDate(file, { age: 'newest' });
} catch (err) {
  if (err instanceof Error && err.message.includes('the file does not exist')) {
    // file was removed mid-build; skip it or refresh the file list
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getFileCommitDate() with a path to a file that has been deleted, moved, or never existed. Commonly the path comes from a glob over docs content; if a file disappears between the glob and the per-file git query (race during dev hot-reload, partial sync, or an interrupted write) this fires.

Common situations: A doc file is deleted or renamed mid-build (dev server watching). An external script generates file lists that are stale by the time the build runs. A path with a typo or wrong casing that points at nothing. Cross-platform path separators (backslash on Windows) producing paths that do not exist.

Related errors


AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12). Data as JSON: /api/errors/8e2ac1a072f519fb. Report an issue: GitHub.