What are Yarn and pnpm, and how does CI install with each?
IntermediateConceptNode.js builds (npm, package.json)
Answer
Short answer
They're alternative package managers to npm. Yarn (classic v1 and modern Berry v2+) and pnpm are faster, and pnpm saves lots of disk space by storing each package version once and linking it. The rule in CI: use the tool that matches the lockfile in the repo, with its frozen/immutable install mode.
Table
| Lockfile | Tool | CI command |
|---|---|---|
package-lock.json |
npm | npm ci |
yarn.lock (v1) |
Yarn classic | yarn install --frozen-lockfile |
yarn.lock (v2+) |
Yarn Berry | yarn install --immutable |
pnpm-lock.yaml |
pnpm | pnpm install --frozen-lockfile |
Getting the right version
corepack enable # built into Node; reads "packageManager" in package.json
# "packageManager": "[email protected]"
GitHub Actions example
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with: { node-version: 22, cache: pnpm }
- run: pnpm install --frozen-lockfile
- run: pnpm build
What to say in the interview
"Whatever lockfile is committed decides the tool. In CI we use corepack to get the pinned version and the frozen-lockfile install so builds are deterministic. pnpm is popular in monorepos for its speed and disk efficiency."
More on Node.js builds (npm, package.json)
What is package.json and what does it contain?BeginnerHow do you build and run a Node.js application?BeginnerWhat is the difference between npm install and npm ci?BeginnerWhy must package-lock.json be committed to Git?BeginnerWhat is the difference between dependencies and devDependencies?BeginnerWhat do the ^ and ~ symbols mean in package.json versions?Beginner