A Quick Comparison of Mainstream Node.js Package Managers: pnpm vs bun vs npm vs yarn
Does pnpm really know how to play space magic? In a single project, its leading advantage is only this small? Node.js 20 has fattened up npm, and now who dares to say npm is useless? This test result is really baffling.
目录9 个章节
Frontend
I've been working on frontend projects a lot recently, and I switched my environment from the original Node.js to bun, which gave me an incredibly fast experience.
When I needed to maintain the StarBlog Vue Admin project today, I had to install dependencies again. This gave me a sudden idea—I wanted to compare the disk space usage of different package managers, which led to the tests in this article.
This article focuses on testing the disk space usage of node_modules.
Testing Environment
-
Operating System: Windows10 22H2 10.0.19045
-
Test Project: StarBlog Vue Admin
-
Node.js Environment: v20.18.1
This is a Vue2-based admin project, which can be a good representation of some legacy frontend projects.
The analysis space command used is:
"{0:N2} MB" -f ((Get-ChildItem -Recurse -Force .\node_modules | Measure-Object -Property Length -Sum).Sum / 1MB)
Test Results
| Package Manager | node_modules Space Usage |
|---|---|
| pnpm | 🏆 205.36 MB (most efficient) |
| npm | 209.02 MB |
| yarn | 213.42 MB |
| bun | 234.13 MB (most space used) |
The test results surprised me a bit. npm, once frowned upon by many, has improved so much—it's now quite competitive in both speed and space usage 👍. I guess I haven't used npm in ages 😂 (Well well, how the tables have turned 😄).
PS: By the way,
pnpm devcouldn't start the project properly here, throwing a bunch of errors. I suspect it's a version incompatibility issue—downgrading the Node.js version might solve it, but I can't be bothered to tinker with it. 🥱
Summary
- pnpm's "hard links + global store" mechanism is indeed the strongest in terms of space usage, as expected.
- npm / yarn show little difference for single projects, with similar disk space performance.
- bun is usually faster, but in this test, it actually consumes the most disk space — which also shows that its current optimization for "deduplication/space optimization" is not as good as pnpm, or even npm.
Analysis
Impact of Project Dependency Structure
- Vue2 projects have relatively fixed dependencies, and the package size does not tend to be as large as the combination of Vue3 + Vite, which often involves hundreds or even thousands of small packages.
- In this case, npm's redundancy issue is not significant, so its space usage is not much different from yarn / pnpm / bun (around 200 MB, all on the same order of magnitude).
- The hard-link optimization of pnpm only creates a larger gap in "scenarios with high dependency duplication" (e.g., monorepos, multiple projects reusing dependencies). For a single project, its advantages are "diminished."
Improvements in Node.js 20
- Starting from Node.js 16, the default version of npm has been npm 8+ / 9+, which has significantly improved both performance and disk efficiency.
- Previously, people criticized npm for being slow and taking up too much space—that was the experience during the npm 6/7 era. Now, npm doesn't actually "lag behind" at all in single-project scenarios.
- This is why I feel that "npm isn't as slow as it's rumored to be, and it doesn't take up too much space either."
Installation Speed vs. Disk Space Usage
- bun: Its absolute advantage lies in installation speed, but its space optimization mechanism is not as good as pnpm, leading to the highest disk usage.
- pnpm: Fast installation and saves space, but the advantage isn't significant for a "single project"; its full potential is realized when dependencies are shared across multiple projects.
- npm: With optimizations in Node.js 20, its speed is no longer considered slow. Disk space usage has also been optimized, putting it on par with yarn.
- yarn (classic): Compared to npm, it no longer has a major advantage. Nowadays, more people are switching to yarn berry (v2+), but that setup may have compatibility concerns with older Vue2 projects.
Conclusion
- Single-project scenarios: npm/yarn/pnpm/bun have minimal differences; any choice will suffice.
- Multi-project / monorepo scenarios: pnpm's space advantage becomes dramatically amplified, while npm/yarn/bun will gradually bloat.
- Extreme speed requirements: bun is the fastest, but the trade-off is higher resource usage.
_EOF_
A Quick Comparison of Mainstream Node.js Package Managers: pnpm vs bun vs npm vs yarn
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
纯前端实现词云展示+附微博热搜词云Demo代码
前言 最近工作中做了几个数据可视化大屏项目,其中也有用到了词云展示,以前做词云都是用python库来生成图片显示的,这次用了纯前端的实现~~(Ctrl+V真好用)~~,同时顺手做个微博热搜的词云然后记录一下~ 依赖 echarts 4.x echarts-wordcloud 1.1.3 tips:echarts-wordcloud现在有2.0和1.x两个版本,2.0对应echarts 5.x版本
2021-12-18 · Web前端 · 约 1 分钟
NextJs 与 Tailwind 入门开发笔记
Next.js?React的脚手架罢了,开箱即用,拒绝精神内耗。Tailwind?Bootstrap的替代品,罢了。实际开发中,pnym坑死人,localStorage问题?小菜一碟。
2024-01-27 · Web前端 · 约 1 分钟
使用国内NPM镜像源提高速度
NPM介绍 npm(全称 Node Package Manager,即“node包管理器”)是Node.js默认的、以JavaScript编写的软件包管理系统。 npm可以管理本地项目的所需模块并自动维护依赖情况,也可以管理全局安装的JavaScript工具。 但是由于npm的源在国外,所以国内使用起来动辄10kb/s,甚至根本下载不了,所以使用国内镜像源替代官方源就很有必要了。 国内源 淘宝np
2022-02-25 · Web前端 · 约 1 分钟
Next.js路由段配置选项笔记
Next.js的路由段配置选项?真有这么简单?官方文档写得倒是分散,自己整理下倒也罢了。动态渲染还是静态?缓存策略又该怎么定?开发者还是得自己琢磨。
2025-10-30 · Web前端 · 约 1 分钟
讨论
共 0 条加载评论中…