microsoft/TypeScript · error · Error
patch does not match. ${tsFilePath}: '${parsedPatch}; packag
Error message
patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}' What it means
updateTsFile parses the patch digit out of the `export const version` line in the TS source and compares it to the patch parsed from package.json. A mismatch means the two sources of truth have drifted, so the release would publish inconsistent metadata.
Source
Thrown at scripts/configurePrerelease.mjs:85
* @param {string} tsFileContents
* @param {string} majorMinor
* @param {string} patch
* @param {string} nightlyPatch
* @returns {string}
*/
function updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, nightlyPatch) {
const majorMinorRgx = /export const versionMajorMinor = "(\d+\.\d+)"/;
const majorMinorMatch = majorMinorRgx.exec(tsFileContents);
assert(majorMinorMatch !== null, `The file '${tsFilePath}' seems to no longer have a string matching '${majorMinorRgx}'.`);
const parsedMajorMinor = majorMinorMatch[1];
assert(parsedMajorMinor === majorMinor, `versionMajorMinor does not match. ${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`);
const versionRgx = /export const version(?:: string)? = `\$\{versionMajorMinor\}\.(\d)(-\w+)?`;/;
const patchMatch = versionRgx.exec(tsFileContents);
assert(patchMatch !== null, `The file '${tsFilePath}' seems to no longer have a string matching '${versionRgx.toString()}'.`);
const parsedPatch = patchMatch[1];
if (parsedPatch !== patch) {
throw new Error(`patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}'`);
}
return tsFileContents.replace(versionRgx, `export const version: string = \`\${versionMajorMinor}.${nightlyPatch}\`;`);
}
/**
* @param {string} versionString
* @returns {{ majorMinor: string, patch: string }}
*/
function parsePackageJsonVersion(versionString) {
const versionRgx = /(\d+\.\d+)\.(\d+)($|-)/;
const match = versionString.match(versionRgx);
assert(match !== null, "package.json 'version' should match " + versionRgx.toString());
return { majorMinor: match[1], patch: match[2] };
}
/* eslint-enable no-restricted-syntax */
/**
View on GitHub (pinned to b465fdbfe1)
Solutions
- Align the patch digit in the TS source `export const version` with package.json.
- Use the normal version-bump flow rather than editing files by hand.
- Re-run after correcting whichever file is behind.
Example fix
// before
// package.json: "version": "5.9.3"
// src/compiler/core.ts: export const version = `${versionMajorMinor}.2`;
// after
// src/compiler/core.ts: export const version = `${versionMajorMinor}.3`; Defensive patterns
Strategy: validation
Validate before calling
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
const src = fs.readFileSync(tsFilePath, "utf8");
const pkgPatch = pkg.version.match(/\d+\.\d+\.(\d)/)[1];
const srcPatch = src.match(/export const version(?:\: string)? = `\$\{versionMajorMinor\}\.(\d)/)[1];
if (pkgPatch !== srcPatch) {
throw new Error(`patch mismatch: package.json=${pkgPatch} src=${srcPatch}`);
} Prevention
- Bump both package.json and the src version constant together via one script.
- Add a CI check that the two patch digits agree.
When it happens
Trigger: package.json version was bumped but the src `version` constant wasn't (or vice versa), so their patch digits differ.
Common situations: Hand-editing one file but not the other; cherry-picking a version change across branches; partial version bump.
Related errors
- Unexpected tag name '${tag}'.
- \n '${tsFilePath}' was not updated while configuring for a
- Cannot replace the LKG unless all built targets are present
- Failed to update status comment
- Diagnostic code ${code} appears more than once.
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/3d80b68a7488b26a.
Report an issue: GitHub.