{"record":{"id":"6a6702ba42dec438","repo":"microsoft/TypeScript","slug":"cannot-replace-the-lkg-unless-all-built-targets-ar","errorCode":null,"errorMessage":"Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\n${missingFiles.join(\"\\n\")}","messagePattern":"Cannot replace the LKG unless all built targets are present in directory 'built/local/'\\. The following files are missing:\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Herebyfile.mjs","lineNumber":923,"sourceCode":"\r\n        const expectedFiles = [\r\n            \"built/local/tsc.js\",\r\n            \"built/local/_tsc.js\",\r\n            \"built/local/tsserver.js\",\r\n            \"built/local/_tsserver.js\",\r\n            \"built/local/tsserverlibrary.js\",\r\n            \"built/local/tsserverlibrary.d.ts\",\r\n            \"built/local/typescript.js\",\r\n            \"built/local/typescript.d.ts\",\r\n            \"built/local/typingsInstaller.js\",\r\n            \"built/local/_typingsInstaller.js\",\r\n            \"built/local/watchGuard.js\",\r\n        ].concat(libs().map(lib => lib.target));\r\n        const missingFiles = expectedFiles\r\n            .concat(localizationTargets)\r\n            .filter(f => !fs.existsSync(f));\r\n        if (missingFiles.length > 0) {\r\n            throw new Error(\"Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\\n\" + missingFiles.join(\"\\n\"));\r\n        }\r\n\r\n        await exec(process.execPath, [\"scripts/produceLKG.mjs\"]);\r\n    },\r\n});\r\n\r\nexport const lkg = task({\r\n    name: \"lkg\",\r\n    hiddenFromTaskList: true,\r\n    dependencies: [produceLKG],\r\n});\r\n\r\nexport const cleanBuilt = task({\r\n    name: \"clean-built\",\r\n    hiddenFromTaskList: true,\r\n    run: () => fs.promises.rm(\"built\", { recursive: true, force: true }),\r\n});\r\n\r","sourceCodeStart":905,"sourceCodeEnd":941,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/Herebyfile.mjs#L905-L941","documentation":"produceLKG enumerates a fixed set of expected outputs under built/local/ (tsc.js, _tsc.js, tsserver.js, _tsserver.js, tsserverlibrary.js/.d.ts, typescript.js/.d.ts, typingsInstaller.js, _typingsInstaller.js, watchGuard.js, all lib.*.d.ts, plus localization targets). It refuses to overwrite the LKG if any are missing, preventing a half-built LKG from poisoning the self-host.","triggerScenarios":"Invoking produceLKG after a partial or failed `local` build, or when the localization build hasn't produced its outputs.","commonSituations":"Build interrupted mid-way; localization pipeline skipped; running LKG before all dependencies of `local` finished.","solutions":["Run a clean full build: `hereby local --bundle` (and the localization tasks) before LKG.","Read the missing-files list from the error message and rebuild whichever task owns those files.","If in doubt, `git clean -fdx built/` and rebuild from scratch."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import fs from \"fs\";\nconst expected = [\"built/local/tsc.js\",\"built/local/_tsc.js\",\"built/local/tsserver.js\",\"built/local/_tsserver.js\",\"built/local/tsserverlibrary.js\",\"built/local/tsserverlibrary.d.ts\",\"built/local/typescript.js\",\"built/local/typescript.d.ts\",\"built/local/typingsInstaller.js\",\"built/local/_typingsInstaller.js\",\"built/local/watchGuard.js\"];\nconst missing = expected.filter(f => !fs.existsSync(f));\nif (missing.length) throw new Error(`Build incomplete; missing: ${missing.join(\", \")}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run a full `hereby local --bundle` before LKG.","Include localization builds in the pre-LKG pipeline.","Clean built/ when builds start from an unknown state."],"tags":["build","lkg","validation","localization"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}