Summary of npm, Yarn, and pnpm Package Managers
This article reviews the evolution of Node.js package managers—from npm2's nested dependencies to Yarn's flat model, npm3's symlink approach, and pnpm's content‑addressable store—highlighting their installation commands, advantages, drawbacks, and impact on disk usage and dependency management.
Summary of npm, Yarn, and pnpm Package Managers
In the Node.js ecosystem, package managers are essential for maintaining dependencies between applications and libraries. npm began with npm1, quickly replaced by npm2, which used a nested node_modules structure, causing deep dependency trees, duplicated packages, and path‑length limitations.
npm2
npm2 installs each package’s own node_modules , leading to nested dependencies that increase installation time, disk space consumption, and can exceed Windows path limits. An example installation of koa ( npm install koa ) demonstrates the deep folder hierarchy and redundant copies.
Yarn
Yarn introduced a flat dependency model, placing all packages in the project’s root node_modules , eliminating most duplication and reducing disk usage. However, when multiple versions of a dependency exist, Yarn may still create nested folders to preserve version correctness and provides a lockfile for deterministic installs.
npm3
Released in 2015, npm3 adopted flat dependencies with symbolic links to share packages, reducing nesting and disk usage. It also introduced npm shrinkwrap for lockfiles. Despite these improvements, npm3 can suffer from "ghost dependencies" and disk waste when multiple versions of a package are required.
pnpm
pnpm addresses the remaining issues by using a content‑addressable store, hard links, and symlinks to share a single copy of each package across projects. Installing koa with pnpm add koa creates links to a global store, dramatically saving disk space and installation time. pnpm also supports path and Git references, monorepo workspaces, and provides a pnpm store prune command to clean unused packages.
Conclusion
The article concludes with a comparative summary of each manager’s strengths and weaknesses, emphasizing pnpm’s advantages in space efficiency, speed, and handling of ghost dependencies, while noting Yarn’s speed and npm’s broad ecosystem support.
TAL Education Technology
TAL Education is a technology-driven education company committed to the mission of 'making education better through love and technology'. The TAL technology team has always been dedicated to educational technology research and innovation. This is the external platform of the TAL technology team, sharing weekly curated technical articles and recruitment information.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.