facebook/docusaurus · error · GitNotFoundError
Failed to retrieve git history for "${file}" because git is
Error message
Failed to retrieve git history for "${file}" because git is not installed. What it means
Thrown as a GitNotFoundError by getFileCommitDate() when hasGit() returns false — i.e. running `git --version` did not exit 0 (git binary missing from PATH). getFileCommitDate is the engine behind showLastUpdateTime / showLastUpdateAuthor / enableUpdateTimepot features, all of which require git. The custom error class lets upstream code (getGitCommitInfo) detect this specific case and emit a single warning instead of crashing.
Source
Thrown at packages/docusaurus-utils/src/vcs/gitUtils.ts:131
author: string;
}>;
export async function getFileCommitDate(
file: string,
{
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',
[View on GitHub (pinned to 3f483e80e3)
Solutions
- Install git in the build environment (e.g. apt-get install git, apk add git, dnf install git) and confirm `git --version` succeeds.
- If git is not needed, disable the features that trigger it: set showLastUpdateTime, showLastUpdateAuthor, and enableUpdateTimepot to false in plugin options.
- Ensure the build container's PATH includes the directory containing the git binary.
- Re-run the build; hasGit is memoized per-process so a fresh process is required after installing git.
Example fix
# before — Dockerfile omits git FROM node:20-alpine RUN pnpm build # after FROM node:20-alpine RUN apk add --no-cache git RUN pnpm build
Defensive patterns
Strategy: fallback
Validate before calling
import { execaSync } from 'execa';
function isGitAvailable(): boolean {
try { return execaSync('git', ['--version']).exitCode === 0; }
catch { return false; }
}
if (!isGitAvailable() && siteConfig.showLastUpdateTime) {
console.warn('Git not found; disabling showLastUpdateTime for this build.');
} Try / catch
try {
await getFileCommitDate(file, { age: 'newest' });
} catch (err) {
if (err instanceof GitNotFoundError) {
// git missing: warn once and disable time-related features for the build
}
throw err;
} Prevention
- Install git in every environment that runs the build (add it to Dockerfiles, CI images).
- If a build environment legitimately lacks git, disable showLastUpdateTime / showLastUpdateAuthor / enableUpdateTimepot.
- In custom Dockerfiles, prefer images that ship git or add it explicitly (apk add git, apt-get install git).
When it happens
Trigger: Building Docusaurus with showLastUpdateTime: true (or similar) in an environment without git installed: a fresh CI image, a minimal Docker container, a sandboxed server. hasGit() is memoized so once it returns false every subsequent call short-circuits to this throw.
Common situations: Alpine-based Docker images that do not include git by default. CI containers where git is installed in a later stage but the build runs in an earlier stage. Local machines where git is not on PATH. Detached environments (some serverless build runners) that omit git intentionally.
Related errors
- Couldn't check if this directory is within a Git worktree: $
- Failed to retrieve the git history for file "${file}" with e
- To enable Docusaurus Faster options, your site must add the
- Docusaurus MDX partial files should not contain front matter
- Failed to retrieve git history for "${file}" because the fil
AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12).
Data as JSON: /api/errors/c2c8e3835c9d87c2.
Report an issue: GitHub.