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 许可协议。转载请注明出处!
相关文章
使用mock.js开发假数据接口
参考资料 Mockjs使用 - https://juejin.cn/post/6953199521031520292 http://wll8.gitee.io/mockjs-examples Mokcjs 文档 Vitepress版 - http://mock.pe666.cn/
2022-12-06 · Web前端 · 约 1 分钟
Vue2.x项目整合ExceptionLess监控
前言 一直以来我们都是用Sentry做项目监控,不过前段时间我们的Sentry坏掉了~~(我搞坏的)~~ 但监控又是很有必要的,在sentry修好之前,我想先寻找一个临时的替代方案,同时发现网上关于ExceptionLess的资料少得可怜,ExceptionLess官方的文档也不是很完善,翻了好久文档和源码,于是有了本文…… 关于ExceptionLess 写.NetCore的同学应该不会陌生,这
2022-03-23 · Web前端 · 约 1 分钟
在网页中使用Material-Design图标
什么是Material Design图标 MD大家都听过的吧,就是谷歌的Material Design设计,Material Design图标就是符合 MD设计语言的图标。 本文通过字体的方法在网页中显示Material Design图标。 What are material icons Material design system icons are simple, modern, friend
2021-12-18 · Web前端 · 约 1 分钟
开始开发一个新博客了,复古风Metro风格,顺便diss一下js
emmm 我原本的博客是用wordpress搭建的,当年七牛云还是免费时用它做的CDN,但是现在收费了,如果维持目前的博客流量的话每个月都要支付不少费用,于是只好把七牛云给停了= =,这也导致我博客里面很多图片都访问不了,页面布局也出问题了,不想折腾了,而且wordpress用起来总觉得不顺手,还是自己做一个吧~ 计划 最近刚好在学SpringBoot啥的,本来想用springboot搭建一个博客
2022-07-18 · Web前端 · 约 1 分钟
讨论
共 0 条加载评论中…