Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 36 ยท Performance and Alternatives

Corepack, Bun and Other Alternatives

Pin the package manager with the packageManager field and Corepack, translate commands between npm, Yarn, pnpm and Bun, and compare the alternatives honestly.

Two developers on the same project, two different package managers: one runs npm install, the other pnpm install. Now there are two lockfiles that disagree. Or both use pnpm, but one has version 8 and the other version 10, and the lockfile format flips back and forth in every pull request. This lesson shows how to pin the tool itself, how to translate between the commands, and where alternatives such as Bun and Deno fit.

Commands appear as read-only snippets. The runnable examples parse the packageManager field and translate commands in plain Node.js.

The packageManager field

Add one line to the root package.json:

JSON
{
  "name": "acme",
  "packageManager": "[email protected]+sha512.abcdef..."
}

The format is name@version, optionally followed by +sha512.<hash> of the tool's tarball. It declares which manager and which exact version this project is meant to use. Tools that understand it can refuse to run with the wrong one or fetch the right one for you.

Node.js Stand-in: read the packageManager field

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Corepack

Corepack is a small tool bundled with Node.js (it ships with Node but is not enabled by default; since Node 25 it is no longer bundled and installs from npm with npm i -g corepack). It acts as a transparent shim for yarn and pnpm:

Terminal
corepack enable                 # create the yarn and pnpm shims
corepack prepare pnpm@10.4.1 --activate   # download a specific version once
pnpm install                    # now runs exactly the version from package.json

With packageManager set, running pnpm or yarn inside the project makes Corepack download the pinned version, verify its hash and run it, regardless of what is installed globally. Everyone on the team and in CI then uses the same manager version, which keeps lockfile formats stable. Corepack can also refuse a different manager: run npm install in a project that says pnpm@... and recent npm versions can warn or fail, depending on configuration.

Notes you should know:

  • Corepack manages Yarn and pnpm. npm itself is installed with Node, so pin Node with a version manager (.nvmrc, .node-version, Volta, fnm) and set engines.node.
  • If your CI image does not have Corepack, actions/setup-node and similar steps can enable it, or install the manager directly (npm i -g [email protected]).
  • Some teams prefer a version manager like Volta ("volta": { "node": "...", "pnpm": "..." }) or mise to pin everything in one tool.
  • Yarn Berry can also live inside the repository (yarnPath in .yarnrc.yml pointing at .yarn/releases/yarn-4.x.cjs), which needs no external tool at all.

Translating commands

The three older managers have the same ideas with different words. Bun is included because it follows the npm model closely.

Task npm Yarn (Berry) pnpm Bun
Install all npm install yarn install pnpm install bun install
Strict CI install npm ci yarn install --immutable pnpm install --frozen-lockfile bun install --frozen-lockfile
Add a dependency npm install pkg yarn add pkg pnpm add pkg bun add pkg
Add as dev npm install -D pkg yarn add -D pkg pnpm add -D pkg bun add -d pkg
Remove npm uninstall pkg yarn remove pkg pnpm remove pkg bun remove pkg
Run a script npm run build yarn build pnpm build bun run build
Run a binary once npx cowsay yarn dlx cowsay pnpm dlx cowsay bunx cowsay
Why is this here? npm explain pkg yarn why pkg pnpm why pkg bun why pkg
Update npm update yarn up pnpm update bun update
Audit npm audit yarn npm audit pnpm audit bun audit

Here is a tiny translator that encodes part of the table:

Node.js Stand-in: translate commands between managers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The alternatives

Bun

Bun is a JavaScript runtime, bundler, test runner and package manager in one binary written in Zig. bun install is typically several times faster than npm because it is native code, resolves and fetches in parallel and uses a global cache with hard links (or clonefile on macOS). It reads package.json, understands workspaces and, since version 1.2, writes a text lockfile bun.lock (it used a binary bun.lockb before). Trade-offs: it is younger, a few lifecycle-script and resolution edge cases differ from npm, and adopting it for installs usually means you also consider it as a runtime. You can use bun install while still running your code with Node.

Deno

Deno is a runtime with its own module system (URLs, jsr: and npm: specifiers) and no mandatory node_modules. deno add and deno install work with deno.json, and Deno can run npm packages through npm: imports. It is attractive when you want secure-by-default permissions and TypeScript out of the box; for an existing Node codebase the package managers in this course remain the practical choice.

Others you may meet

  • Yarn Classic (1.x) is in maintenance mode. Existing projects work, but new projects should choose Yarn Berry, pnpm or npm.
  • Rush and Lerna are monorepo orchestrators; modern Lerna wraps Nx and workspaces.
  • JSR (the JavaScript Registry) is a registry that targets TypeScript-first, ESM-only packages, usable from npm, Yarn and pnpm clients.
  • Vendoring: copying dependencies into the repo (or committing Yarn's zip cache) trades repository size for total reproducibility.

Choosing

Quick guide

npm Zero setup, everywhere
Yarn Berry and PnP, plugins
pnpm Fast, strict, monorepos
Bun Fastest installs, all-in-one

All four read package.json and use the npm registry.

1 / 2
  • Default and simplest: npm. It is already on every machine that has Node.
  • Monorepos or many projects on one disk: pnpm.
  • Plugin system, constraints, zero-installs: Yarn Berry.
  • Speed above all, or you already use the Bun runtime: Bun.

Whatever you choose, write it down in packageManager, keep one lockfile, and make CI use the strict install command. Switching later is possible (delete the old lockfile, run the new manager's install, review the diff) but only worth it for a concrete reason.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the packageManager field in package.json do?

    It is a declaration. Corepack (and some other tools) read it to run or enforce the pinned version.
  2. 2. Which package managers does Corepack handle?

    Corepack provides shims for Yarn and pnpm; npm comes with Node itself.
  3. 3. What is the pnpm equivalent of npm ci?

    The frozen-lockfile mode installs only what the lockfile says and fails on drift.
  4. 4. Which statement about Bun is accurate?

    Bun bundles several tools; its installer works with the npm registry and package.json independently of the runtime.

Summary

  • Pin the manager with packageManager and enable Corepack so everyone uses the same version; pin Node separately.
  • npm, Yarn, pnpm and Bun share concepts; the command table is the main translation you need.
  • Bun is the speed-focused all-in-one, Deno is a different runtime, Yarn Classic is legacy.
  • Choose with a reason, keep one lockfile, and use the strict install in CI.

Next: Project: Publish a Small CLI