## TL;DR
The lockfile references a dependency entry that is not actually recorded, usually after a partial or interrupted upgrade. Run pnpm install --force to rewrite the lockfile from the manifests, then verify with a frozen install. Do not patch the lockfile by hand.

## Error

```text
pnpm 'ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY' after a partial upgrade
```

## Steps

1. Try the plain refresh first: pnpm install.
   Expected output: Either the error clears or the missing-dependency error persists.
2. If it persists, force a full rewrite: pnpm install --force.
   Expected output: pnpm rebuilds pnpm-lock.yaml from package.json and the error is gone.
3. Review the rewritten lockfile: git diff pnpm-lock.yaml, watching for version moves beyond the intended upgrade.
   Expected output: The diff is limited to the upgrade's scope.
4. Verify determinism with a frozen install.
   Expected output: The frozen install succeeds, proving the lockfile is now complete.
5. Run the test suite, then commit the lockfile.
   Expected output: Tests pass and CI installs cleanly.

## When to use

- pnpm fails with ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY after an interrupted or partial upgrade
- A plain pnpm install does not clear the missing entry
- The lockfile was generated by an older pnpm version with a different layout

## When not to use

- The error is ERR_PNPM_OUTDATED_LOCKFILE; a plain pnpm install refresh is enough
- The lockfile is simply absent; generate it fresh instead of forcing
- A tarball fails to download; that is a registry or network problem

## Variant phrasings

### pnpm lockfile missing dependency after a killed upgrade
The interrupted-upgrade shape; the lockfile is half-written and a forced install rebuilds it.

### ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY on a fresh clone
Suggests the committed lockfile was already broken; the forced rewrite repairs it, then commit the fix.

### pnpm install --force to rebuild a corrupt lockfile
The general repair: --force re-resolves everything from the manifests.

## Why it happens

A partial upgrade writes some lockfile entries and not others, or two processes interleave writes, leaving references that point at entries that were never recorded. pnpm validates the lockfile before installing and aborts on the dangling reference rather than guess. A forced install discards the broken record and re-resolves from scratch.

## Edge cases

- A forced install can move many versions at once; review the diff before committing.
- If the missing entry comes from a private registry package, ensure auth works before the rewrite or the rebuild fails differently.
- pnpm version mismatches between the agent and CI can reintroduce the error; pin the pnpm version in the packageManager field or CI config.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_wyBWXObu6IhK_Iyw0WSmbA
