microsoft/TypeScript · error · Error

The baseline file ${relativeFileName} has changed. (Run "her

Error message

The baseline file ${relativeFileName} has changed. (Run "hereby baseline-accept" if the new baseline is correct.)

What it means

Thrown by writeComparison (harnessIO.ts:1486) when a baseline test's actual output differs from the recorded reference and BaselineOptions.PrintDiff is set. The full unified diff is appended to the message via Diff.createTwoFilesPatch. The actual file is written under tests/baselines/local for inspection.

Source

Thrown at src/harness/harnessIO.ts:1486

        createDirectoryStructure(IO.directoryName(actualFileName)!); // TODO: GH#18217

        // Delete the actual file in case it fails
        if (IO.fileExists(actualFileName)) {
            IO.deleteFile(actualFileName);
        }

        const encodedActual = Utils.encodeString(actual);
        if (expected !== encodedActual) {
            if (actual === noContent) {
                IO.writeFile(actualFileName + ".delete", "");
            }
            else {
                IO.writeFile(actualFileName, encodedActual);
            }
            const errorMessage = getBaselineFileChangedErrorMessage(relativeFileName);
            if (opts && opts.PrintDiff) {
                const patch = Diff.createTwoFilesPatch("Expected", "Actual", expected, actual, "The current baseline", "The new version");
                throw new Error(`${errorMessage}${ts.ForegroundColorEscapeSequences.Grey}\n\n${patch}`);
            }
            else {
                if (!IO.fileExists(expected)) {
                    throw new Error(`New baseline created at ${IO.joinPath("tests", "baselines", "local", relativeFileName)}`);
                }
                else {
                    throw new Error(errorMessage);
                }
            }
        }
    }

    function getBaselineFileChangedErrorMessage(relativeFileName: string): string {
        return `The baseline file ${relativeFileName} has changed. (Run "hereby baseline-accept" if the new baseline is correct.)`;
    }

    export function runBaseline(relativeFileName: string, actual: string | null, opts?: BaselineOptions): void { // eslint-disable-line no-restricted-syntax
        const actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Read the diff in the error message; if the new output is correct, run `hereby baseline-accept` to promote tests/baselines/local → tests/baselines/reference.
  2. If the diff is unexpected, revert the source change that caused it or fix the compiler regression before accepting.
  3. Re-run just the failing test (`hereby <test-task> --fix`) to confirm the new local file matches what you intend to accept.
  4. Commit the regenerated reference baselines together with the code change in the same atomic commit.

Example fix

# before — test fails because reference is stale
$ hereby test-compiler
Error: The baseline file ... has changed.

# after — accept the intended change
$ hereby baseline-accept
$ hereby test-compiler   # now green
Defensive patterns

Strategy: validation

Validate before calling

// In CI, detect drift and fail with a dedicated exit code instead of a raw throw.
const expected = IO.readFile(referencePath);
if (expected !== undefined && expected !== Utils.encodeString(actual)) {
  console.error(`Baseline drift in ${relativeFileName}. Run: hereby baseline-accept`);
  process.exit(BASELINE_DRIFT_EXIT_CODE);
}

Try / catch

try {
  runBaseline(relativeFileName, actual, { PrintDiff: true });
} catch (e) {
  if (e.message.includes('baseline file') && e.message.includes('baseline-accept')) {
    // surface a CI-friendly hint, then re-throw or mark the test as baseline-pending
    throw Object.assign(new Error('BASELINE_DRIFT: ' + e.message), { baselineDrift: true });
  }
  throw e;
}

Prevention

When it happens

Trigger: A test that calls runBaseline/runMultifileBaseline produces content that no longer byte-matches the committed file under tests/baselines/reference, and the harness is configured with PrintDiff. Common after a real behavior change in the compiler or after editing a test's inputs.

Common situations: Intentional compiler behavior change (e.g. a diagnostic rewrite, new emit format); updating lib.d.ts; changing pretty-printing; any PR that legitimately alters output — the reference baseline must be regenerated.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/dca28d2c632d4fa2. Report an issue: GitHub.