{"record":{"id":"3d80b68a7488b26a","repo":"microsoft/TypeScript","slug":"patch-does-not-match-tsfilepath-parsedpatc","errorCode":null,"errorMessage":"patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}'","messagePattern":"patch does not match\\. (.+?): '(.+?); package\\.json: '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/configurePrerelease.mjs","lineNumber":85,"sourceCode":" * @param {string} tsFileContents\r\n * @param {string} majorMinor\r\n * @param {string} patch\r\n * @param {string} nightlyPatch\r\n * @returns {string}\r\n */\r\nfunction updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, nightlyPatch) {\r\n    const majorMinorRgx = /export const versionMajorMinor = \"(\\d+\\.\\d+)\"/;\r\n    const majorMinorMatch = majorMinorRgx.exec(tsFileContents);\r\n    assert(majorMinorMatch !== null, `The file '${tsFilePath}' seems to no longer have a string matching '${majorMinorRgx}'.`);\r\n    const parsedMajorMinor = majorMinorMatch[1];\r\n    assert(parsedMajorMinor === majorMinor, `versionMajorMinor does not match. ${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`);\r\n\r\n    const versionRgx = /export const version(?:: string)? = `\\$\\{versionMajorMinor\\}\\.(\\d)(-\\w+)?`;/;\r\n    const patchMatch = versionRgx.exec(tsFileContents);\r\n    assert(patchMatch !== null, `The file '${tsFilePath}' seems to no longer have a string matching '${versionRgx.toString()}'.`);\r\n    const parsedPatch = patchMatch[1];\r\n    if (parsedPatch !== patch) {\r\n        throw new Error(`patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}'`);\r\n    }\r\n\r\n    return tsFileContents.replace(versionRgx, `export const version: string = \\`\\${versionMajorMinor}.${nightlyPatch}\\`;`);\r\n}\r\n\r\n/**\r\n * @param {string} versionString\r\n * @returns {{ majorMinor: string, patch: string }}\r\n */\r\nfunction parsePackageJsonVersion(versionString) {\r\n    const versionRgx = /(\\d+\\.\\d+)\\.(\\d+)($|-)/;\r\n    const match = versionString.match(versionRgx);\r\n    assert(match !== null, \"package.json 'version' should match \" + versionRgx.toString());\r\n    return { majorMinor: match[1], patch: match[2] };\r\n}\r\n/* eslint-enable no-restricted-syntax */\r\n\r\n/**\r","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/scripts/configurePrerelease.mjs#L67-L103","documentation":"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.","triggerScenarios":"package.json version was bumped but the src `version` constant wasn't (or vice versa), so their patch digits differ.","commonSituations":"Hand-editing one file but not the other; cherry-picking a version change across branches; partial version bump.","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."],"exampleFix":"// before\n// package.json:  \"version\": \"5.9.3\"\n// src/compiler/core.ts: export const version = `${versionMajorMinor}.2`;\n\n// after\n// src/compiler/core.ts: export const version = `${versionMajorMinor}.3`;","handlingStrategy":"validation","validationCode":"const pkg = JSON.parse(fs.readFileSync(\"package.json\", \"utf8\"));\nconst src = fs.readFileSync(tsFilePath, \"utf8\");\nconst pkgPatch = pkg.version.match(/\\d+\\.\\d+\\.(\\d)/)[1];\nconst srcPatch = src.match(/export const version(?:\\: string)? = `\\$\\{versionMajorMinor\\}\\.(\\d)/)[1];\nif (pkgPatch !== srcPatch) {\n  throw new Error(`patch mismatch: package.json=${pkgPatch} src=${srcPatch}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bump both package.json and the src version constant together via one script.","Add a CI check that the two patch digits agree."],"tags":["release","version","validation","prerelease"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}