Question presented to candidate: "A teammate's install produces a different lockfile than yours. What tool exists to stop that?"
What a strong answer should cover:
- Corepack ships bundled with Node.js itself (since Node 16.9, promoted further since) β it is not something you
npm installseparately. - It does not implement npm, Yarn, or pnpm itself. It is a thin shim: when you run
yarnorpnpm, Corepack intercepts the command and downloads/runs the exact version the project declares. - That version is declared in
package.json's"packageManager"field β e.g."packageManager": "pnpm@9.1.0"β so it travels with the repo, not with each developer's global install. - The practical problem it solves: without it, one developer's globally-installed Yarn 1 and another's Yarn 4 produce different lockfiles and different install behaviour from the same
package.json. - It must be enabled once per machine (
corepack enable) before it will intercept commands; a project declaring apackageManagerfield does nothing on a machine where Corepack is disabled. - Its status is not settled forever β a version of Node briefly shipped it as opt-out-by-default and then reversed course to opt-in; version-specific defaults should be checked against the Node release actually in use rather than assumed.
Clarifying questions expected:
- "Which Node version is the team standardised on, and is Corepack enabled there?" β the defaults have shifted between releases.
- "Is the packageManager field actually committed to package.json?" β the whole mechanism does nothing without it.
Code / implementation expected: Optional. Showing the packageManager field and the enable command is the substance.