microsoft/TypeScript · error · Error

Cannot replace the LKG unless all built targets are present

Error message

Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:
${missingFiles.join("\n")}

What it means

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.

Source

Thrown at Herebyfile.mjs:923

        const expectedFiles = [
            "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",
        ].concat(libs().map(lib => lib.target));
        const missingFiles = expectedFiles
            .concat(localizationTargets)
            .filter(f => !fs.existsSync(f));
        if (missingFiles.length > 0) {
            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"));
        }

        await exec(process.execPath, ["scripts/produceLKG.mjs"]);
    },
});

export const lkg = task({
    name: "lkg",
    hiddenFromTaskList: true,
    dependencies: [produceLKG],
});

export const cleanBuilt = task({
    name: "clean-built",
    hiddenFromTaskList: true,
    run: () => fs.promises.rm("built", { recursive: true, force: true }),
});

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Run a clean full build: `hereby local --bundle` (and the localization tasks) before LKG.
  2. Read the missing-files list from the error message and rebuild whichever task owns those files.
  3. If in doubt, `git clean -fdx built/` and rebuild from scratch.
Defensive patterns

Strategy: validation

Validate before calling

import fs from "fs";
const 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"];
const missing = expected.filter(f => !fs.existsSync(f));
if (missing.length) throw new Error(`Build incomplete; missing: ${missing.join(", ")}`);

Prevention

When it happens

Trigger: Invoking produceLKG after a partial or failed `local` build, or when the localization build hasn't produced its outputs.

Common situations: Build interrupted mid-way; localization pipeline skipped; running LKG before all dependencies of `local` finished.

Related errors


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