Guide
npm vs pnpm vs Yarn vs Bun: Package Managers




Compare npm, pnpm, Yarn and Bun install workflows: dependency isolation, workspaces, lockfiles, CI caching and migration checks for JavaScript teams and projects.
Contents
Contents
TL;DR
Choose pnpm when workspace dependencies and shared storage are the main problems; keep npm when the existing workflow works and switching adds little value. Choose Yarn for its configurable linkers and a deliberate Plug'n'Play workflow. Evaluate Bun install separately from the Bun runtime: it works in Node.js projects, writes a text lockfile, and supports isolated installs. Measure your own CI workload before switching for speed.
Quick decision table
| Package | Release used for this comparison | Dependency layout | Lockfile | CI install |
|---|---|---|---|---|
| npm | 12.2.2 | Conventional node_modules | package-lock.json | npm ci |
| pnpm | 12.18.0 | Linked dependencies backed by a shared store | pnpm-lock.yaml | pnpm install --frozen-lockfile |
| Yarn | 4.18.1 | PnP, node-modules or pnpm linker | yarn.lock | yarn install --immutable |
| Bun | 1.4.4 | Hoisted or isolated installs | bun.lock | bun install --frozen-lockfile |
The npm registry metadata, pnpm metadata, modern Yarn distribution and Bun metadata identify these releases. The npm package named yarn still points to Yarn Classic 1.22.22; installing it globally does not select modern Yarn. Check the executable version inside the repository before interpreting a benchmark or following migration instructions.
Key takeaways
- Dependency layout affects which undeclared imports happen to work. Treat failures exposed by stricter resolution as dependency declarations to investigate.
- A lockfile and a pinned package manager solve different problems. Keep both the dependency graph and the executable reproducible.
- Bun install can serve a Node.js application. A package-manager change does not require replacing the runtime, test runner or bundler.
- A shared cache helps only when restoring it costs less than fetching and rebuilding the dependencies it saves.
npm: keep a working baseline
npm is a reasonable choice for a project that already installs reliably, especially when onboarding and existing automation matter more than changing dependency layout. Before switching, inspect where CI spends its time. Downloading tarballs, compiling native modules and running application builds are different costs; replacing the installer cannot be assumed to improve all of them.
Use npm ci in automation with a committed package-lock.json. The npm ci documentation specifies that manifest/lockfile mismatches fail rather than updating the lock. It removes an existing node_modules directory and does not rewrite the manifest or lockfile. Keep resolution flags consistent between the lockfile-generation step and CI; a lock generated with different peer-dependency settings may need the same settings to install.
npm workspaces cover repositories that need local package linking and commands scoped to a workspace. They do not replace a build scheduler. If dependency installation is fine but builds repeat unnecessary work, investigate the task graph before replacing npm. See monorepo build tools for that separate decision.
Do not add --legacy-peer-deps merely to make a failing install green. First identify the incompatible dependency and decide whether the peer contract is valid. Otherwise the repository records an exception without recording why its dependency combination is safe.
pnpm: explicit dependencies and shared storage
pnpm's linked node_modules layout uses files from a content-addressable store and symbolic links to represent the dependency graph. This makes shared storage useful across projects and reduces accidental access to packages that only another dependency declared. It does not establish a fixed percentage of disk savings: filesystem behavior, package overlap and retained store entries all affect the result.
For a migration, expect undeclared imports to become visible. If an application imports a formatter that arrived through another tool, declare that formatter where it is used. Broad hoisting can make the symptom disappear while preserving the hidden coupling. Use a narrowly justified compatibility setting when a third-party tool needs it, and keep that exception documented.
pnpm 12 also changes setup assumptions. Its installation documentation describes a native executable that does not need Node.js after installation; application scripts may still need Node.js. Configuration belongs in pnpm-workspace.yaml for settings such as nodeLinker and hoisting. The settings reference limits .npmrc to registry, authentication and related connection settings. Copying an old pnpm .npmrc example without reviewing it can leave intended behavior unconfigured.
Workspaces and local dependency contracts
Declare workspace paths explicitly and use the workspace protocol when a dependency must resolve locally. A reference such as "@example/ui": "workspace:*" expresses that requirement instead of silently accepting a registry package with a matching name. Review the packed manifest before publishing shared packages; development linking and consumer installation are different checks.
# pnpm-workspace.yaml
packages:
- 'apps/*'
- 'packages/*'
# Target a workspace by its package.json name
pnpm --filter @example/web build
pnpm install --frozen-lockfile
A package manager links dependencies; a task runner schedules builds and caches outputs. Keep those responsibilities clear when diagnosing a monorepo. For a focused configuration walkthrough, use the pnpm catalogs guide; catalogs address shared version declarations rather than choosing a package manager.
Yarn: choose the linker deliberately
Modern Yarn is not synonymous with PnP. Its install modes include PnP, a conventional node-modules linker and a pnpm-style linker. A team can keep Yarn's workflow while selecting the layout its tools support. The meaningful comparison includes the linker configuration, not just the word “Yarn.”
PnP replaces the traditional node_modules tree with a loader that resolves dependencies from Yarn's package map. Evaluate editor integration, test runners, native dependencies and tools that scan node_modules before committing to it. A missing declaration may require fixing your manifest or adding a targeted package extension; changing imports from require to import is not a general PnP compatibility fix.
Start an existing conventional project with the node-modules linker if reducing migration variables matters:
# .yarnrc.yml
nodeLinker: node-modules
Use the Yarn installation workflow to select modern Yarn and record the version in the project. Avoid a configuration that refers to a .yarn/releases file unless that file is actually checked in. Another developer needs to be able to reproduce the installation from the repository, not from a release file left on your machine.
Yarn also provides JavaScript constraints to enforce rules across workspace manifests, such as consistent dependency ranges. Keep these checks separate from installation and test their rules before enabling automatic fixes.
Zero-installs require a cache policy
Yarn's cache strategies distinguish a global cache from a repository-local offline mirror. Zero-installs combine a checked-in cache with PnP artifacts so switching branches can avoid a conventional install step. Native dependencies can still require rebuilding. Decide whether storing dependency archives in Git fits your repository size and review policy.
For automation, yarn install --immutable rejects lockfile changes. Yarn install also documents --immutable-cache and --check-cache; these address different concerns about cache changes and refetching verification. In a zero-install project accepting external contributions, review the cache-validation workflow along with the lockfile. A fast checkout is useful only if the cache is trustworthy and complete.
Bun install: test the installer separately
Bun install works with an existing package.json in a Node.js project. You can keep Node.js as the production runtime and retain the current test and build commands. Test that narrower change before attempting a runtime migration; it gives failures a smaller set of possible causes.
The current lockfile is text-based bun.lock. Old examples calling bun.lockb the only Bun lockfile are stale. Keep the generated lock and use frozen installs in CI. Review registry settings, private scopes, patches and native build steps during adoption rather than assuming command similarity proves identical behavior.
Bun supports isolated installs, including a default for new workspace projects using the documented lockfile configuration. Existing projects may retain hoisted behavior. State the linker when evaluating dependency isolation; Bun is not limited to a flat dependency tree.
bun install --linker isolated
bun install --frozen-lockfile
# Continue to run the application with its existing Node.js command
node server.js
Installed dependency lifecycle scripts have a trust policy in Bun. If a native module is missing its generated binary after migration, inspect the blocked scripts and the package's instructions before changing trust settings. Approve only packages whose install behavior you have reviewed; enabling every script discards the reason for having a policy.
Lockfiles, versions and CI caching
Commit one authoritative lockfile for a project unless separate subprojects intentionally use separate managers. When a different installer creates another lock, investigate before merging it. Two lockfiles can describe different dependency graphs even when package.json is unchanged.
Pin the package manager in the repository and provision that same version in CI. For example:
{
"packageManager": "pnpm@12.18.0"
}
The field communicates a choice; the invoking tool must honor it. Corepack manages supported package-manager versions, but is no longer distributed with Node.js starting with Node 25. Do not assume corepack enable will exist on a fresh runner. Follow your manager's supported installation path and verify the executable version after setup.
Cache downloaded package content independently from build outputs. Key caches by the relevant lockfile, platform and toolchain where required, and confirm the cache path from the manager rather than copying a historical hardcoded location. Native modules introduce architecture and runtime dependencies that a source-only cache may not capture.
Keep the frozen-install check even with a cache hit. Cache restoration does not prove the manifest matches the lock. Also test an empty-cache run: a build that works only with a developer's old cache is not reproducible onboarding.
Migration notes: a reversible evaluation
Start on a branch with a clean baseline build. Record the old install command, package-manager version and lockfile. Keep the production runtime fixed and use a representative application, including native packages, private dependencies and workspace imports.
For npm or Yarn to pnpm, pnpm import can seed a pnpm lockfile from a supported source lock. It is a fresh resolution that prefers source versions, not a guarantee of identical output. Declare workspace paths first, import, then inspect the resolved changes before installing and running checks.
pnpm import
pnpm install --frozen-lockfile
pnpm run build
Run the project's real tests, type checks, production build and packaging checks. In a library workspace, install the packed artifact into a separate consumer: local links can conceal missing files or undeclared dependencies. Test a fresh clone with no cache before removing the previous lockfile from the candidate branch.
Move setup instructions, deployment commands and cache configuration together. Decide who owns the change and how to revert it. Keep dependency upgrades in a separate change when possible so an install failure can be attributed to the new manager rather than a simultaneous package update. For package patches, retain the dedicated patching comparison and verify each patch still applies after import.
Security and dependency risk
Dependency isolation catches undeclared imports; it is not an operating-system sandbox. A malicious install script can still access resources allowed to its process. Do not describe separate workspace node_modules trees as a security barrier against code execution.
For pnpm, approve-builds records dependency build decisions in project configuration. Review the resulting allowBuilds or permissions entries rather than copying an old package.json allowlist. If a required native dependency fails, inspect the policy and approve that dependency deliberately.
For published libraries, npm provenance links an artifact to its source and build process. It is useful supply-chain evidence, but does not certify that the source is safe.
Use advisory scanning, review dependency changes and control install scripts according to the application's threat model. A development dependency can affect production through the build pipeline, so excluding it from runtime scans does not make it harmless. Conversely, an advisory's severity alone does not prove your application reaches the affected code.
Lockfile integrity verifies expected package content; it does not prove that content is benign. Review newly introduced dependencies, registry sources and unexpected install hooks. Read the npm supply-chain guide for the broader process, and use the npm/pnpm comparison for package signals rather than treating CLI download counts as adoption totals.
Methodology: measure the workload you run
This guide does not publish a universal install-speed ranking. Previous versions included timing tables without a reproducible fixture, hardware specification or retained raw results; those numbers cannot support a decision. Vendor speed claims are also specific to their chosen workload.
Decision matrix for a team trial
Use the following evaluation matrix to plan a team trial. Record failures alongside elapsed time; an install that skips a required build step is not comparable to a working install.
| Trial | Hold constant | Record before choosing |
|---|---|---|
| Fresh machine | Application commit, registry, OS, CPU, runtime | Download, extraction and native-build time; final test result |
| Warm content cache | Same fixture and manager version | Cache restore cost plus install time |
| Dependency change | Same declared version change | Lockfile churn, resolution differences and review effort |
| Workspace consumer | Same packed library and consumer | Missing dependencies, linked-only behavior and publish output |
| CI rebuild | Same runner and production command | Total job duration and artifact correctness |
Repeat trials instead of treating a single run as representative. Keep exact tool versions and raw logs with the fixture. Measure physical storage carefully when links and shared stores are involved; summing directory sizes can count shared content repeatedly. Evaluate maintenance velocity by whether required fixes and supported runtime updates reach your workflow, rather than by raw release counts.
FAQ
Must I move to the Bun runtime to use Bun install?
No. Bun documents its installer for existing Node.js projects. Keep the runtime fixed during an installer trial and test the resulting dependency tree with your existing commands.
Does modern Yarn require PnP?
No. Yarn supports multiple stable linkers. Select the node-modules linker when that is the layout your tools require, and evaluate PnP as a separate change.
Which manager should a team keep?
Keep the current manager when installs are reliable and the alternative has no measured benefit. Prefer pnpm for dependency declaration discipline and shared storage, Yarn for a deliberate linker/cache workflow, or Bun install after a representative compatibility trial. The smallest migration is often improving the existing CI install command.
When to use which
Choose npm for an established workflow with little install friction. Choose pnpm when workspace contracts and shared storage justify the migration work. Choose Yarn when the team wants its linkers, workspace features or zero-install approach and will maintain the associated configuration. Choose Bun install when a trial proves it improves the actual project while preserving the required runtime and build behavior.
Source notes and related guides
The linked official documentation supports each tool's behavior; the registry records support the release table. Recommendations are editorial judgments about those behaviors, not measured speed or adoption rankings. The evaluation matrix is a proposed test plan, not a claim that PkgPulse ran those trials.
For focused follow-through, see workspace layout comparisons, pnpm catalogs and package-manager runners. They answer configuration and invocation questions beyond this choice of installer.