react/react · error · Error

Could not find build/COMMIT_SHA file. Did you run scripts/re

Error message

Could not find build/COMMIT_SHA file. Did you run scripts/release/download-experimental-build.js script?

What it means

To produce a build version string, `utils.js` first tries `git show` for the commit hash. In an environment without git context (e.g. Mozilla's git-archive build), it falls back to reading `build/COMMIT_SHA`. If that file does not exist, it throws pointing at `scripts/release/download-experimental-build.js`, which is what writes the file during experimental-build packaging.

Source

Thrown at packages/react-devtools-extensions/utils.js:27

const {existsSync, readFileSync} = require('fs');
const {resolve} = require('path');

const GITHUB_URL = 'https://github.com/facebook/react';

function getGitCommit() {
  try {
    return execSync('git show -s --no-show-signature --format=%h')
      .toString()
      .trim();
  } catch (error) {
    // Mozilla runs this command from a git archive.
    // In that context, there is no Git context.
    // Using the commit hash specified to download-experimental-build.js script as a fallback.

    // Try to read from build/COMMIT_SHA file
    const commitShaPath = resolve(__dirname, '..', '..', 'build', 'COMMIT_SHA');
    if (!existsSync(commitShaPath)) {
      throw new Error(
        'Could not find build/COMMIT_SHA file. Did you run scripts/release/download-experimental-build.js script?',
      );
    }

    try {
      const commitHash = readFileSync(commitShaPath, 'utf8').trim();
      // Return short hash (first 7 characters) to match abbreviated commit hash format
      return commitHash.slice(0, 7);
    } catch (readError) {
      throw new Error(
        `Failed to read build/COMMIT_SHA file: ${readError.message}`,
      );
    }
  }
}

function getVersionString(packageVersion = null) {
  if (packageVersion == null) {

View on GitHub (pinned to 22e4f993c7)

Solutions

  1. Run `node scripts/release/download-experimental-build.js` (per your release flow) to write `build/COMMIT_SHA` before building.
  2. If building from a real checkout, ensure the build runs inside the git repo so the `git show` fallback succeeds.
  3. Manually create `build/COMMIT_SHA` containing the desired commit hash as a last resort.

Example fix

# before
yarn build:extension   # build/COMMIT_SHA missing → throws

# after
node scripts/release/download-experimental-build.js
yarn build:extension
Defensive patterns

Strategy: validation

Validate before calling

import {existsSync} from 'fs';
import {resolve} from 'path';

function ensureCommitSha() {
  const p = resolve(__dirname, '..', '..', 'build', 'COMMIT_SHA');
  if (!existsSync(p)) {
    throw new Error(
      'Missing build/COMMIT_SHA. Run: node scripts/release/download-experimental-build.js',
    );
  }
  return p;
}

Type guard

function hasCommitShaFile(dir) {
  return existsSync(resolve(dir, 'build', 'COMMIT_SHA'));
}

Try / catch

try {
  version = getVersionString();
} catch (e) {
  if (e?.message?.includes('COMMIT_SHA')) {
    console.error('Run scripts/release/download-experimental-build.js first.');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the DevTools extension build (Yarn scripts that call `getVersionString`/commit-hash helpers) outside a git checkout AND without having first run the experimental-build download script. CI environments that use a git archive (no `.git`) and skip the download step.

Common situations: Building the Firefox extension from a Mozilla source archive. Building from a tarball release rather than a git clone. Fresh clone where `build/` was never populated.

Related errors


AI-assisted analysis of react/react@22e4f993c7 (2026-08-12). Data as JSON: /api/errors/37adc19d81f5433a. Report an issue: GitHub.