Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (2024)

Yarn, NPM and PNPM are package managers from the JavaScript world. Everyone who downloads Node.js has NPM, so it's the most commonly used, yarn was created by Meta and PNPM is the newest and fastest. Here’s a detailed look at them.

Advantages and Disadvantages of NPM (Node Package Manager)

NPM is the default package manager for Node.js, it’s simple to use, and tends to run with few issues. Because of its default nature, NPM has amassed a robust community of users that can be a great use should you run into any issues. Although largely problem free, NPM does have some disadvantages.

Sequential installation certainly falls into the disadvantages category - packages are installed sequentially, which increases installation time. Another disadvantage is the NPM audit. For a good rundown of the issues with this, check out this piece, NPM Audit: Broken by Design, on the overreacted site. In short, you may get critical errors during installation that scare you, but the critical error might be that a would-be attacker could have full access to your computer. If this is really an issue, you likely have a whole different set of (much more severe) problems.

Advantages and disadvantages of yarn

Yarn's downloads are solved in parallel, making it much faster. It offers an out-of-the-box offline mode, which is nice when your internet goes down, and the plug-n-play feature tends to be quite useful.

Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (1)

It’s no mystery that node_modules are the heaviest objects in the universe, but maybe it doesn’t have to be that way.

Using hoisting in Yarn

With Yarn, Meta has made a pretty good attempt at solving some key problems with managing node modules. Packages are usually huge and take a long time to copy, delete, or otherwise manipulate. The problem arises when a package has other dependencies, and those in turn have other dependencies and so on, making the dependency tree unnecessarily deep. Sometimes, duplicate versions of the same packages can occur. To avoid this, Yarn uses a technique called hoisting.

Hoisting spreads common packages as far up the tree as possible so other packages can share them as well, thus eliminating the need to do so much downloading and copying. However, this has an interesting drawback - you might accidentally import a function from a subpackage that was installed by the library you were using, not by you. Most modern IDEs catch this, but it’s worth looking into.

Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (2)

Another potential downside is that hoisting uses semver, and this can lead to problems if any of the packages use it incorrectly. For example, it will mark a major change (major change X.x.x) that breaks the same compatibility as a minor change (minor change x.X.x). Yarn, unaware that something might break, then downloads that version and the problem is gone. This is often mentioned on Github for problem packages.

That's why Yarn came up with Plug'n'Play (PnP). PnP eliminates the node_modules folder, storing everything in a global directory. In the project we only have a .pnp.cjs that contains the links (explained below), and a PnP loader that tells you how to load them. This allows us to share between several projects, so we don't have to download and install over and over again. For example, if you have a lot of projects in Next.js, you don't want to download it again. PnP maintains one installation globally.

The Yarn Plug'n'Play implementation uses so-called symlinks, i.e. native links to files. There are two types:

  1. A soft link that becomes non-functional when moving the file
  2. A hard link that maintains the link even after the file is moved.

It’s important to point out that Yarn PnP doesn't work on all packages, which can be tricky. You’ll inevitably say to yourself: "React Native, it's actually a very big package, a piece, a huge library, I'll use PnP." But this doesn't work because React Native uses its own Metro builder that uses symlinks.

If you don't want to use PnP, you can set the node-linker mode in the configuration file and you will also get the aforementioned advantages, including speed.

Advantages and disadvantages of PNPM (Performant NPM)

PNPM is the newest and fastest package manager. It works quite similarly to Yarn's PnP in that it also uses symlinks. What's pretty cool is that it doesn't download entire packages, only the differences between versions. So I don't have to download the whole library.

Another nice feature is that when you use PNPM it will tell you in the console how many packages you're reusing and how much disk space you've saved, so if recycling is your thing, you’ll like this feature.

PNPM has the same drawback as PnP - namely that it may not support all packages.

Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (3)

The node_modules structure of PNPM is easy to read and nicely done - what's a package, what's a link (see image above), etc, is all quite clear.

Package manager speed comparison

The graph below shows that NPM is usually the slowest. Interestingly, although Yarn PnP and PNMP use similar technology, there are some clear differences in speed.

Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (4)

Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (5)

The source of the chart is directly from the PNP"M site, so there can certainly be some bias. The measurement takes place every day, and you can always look at the current measurement and its methodology.

Experimental Node.js Features: CorePack

CorePack turns on in the console and aims to eliminate the need to install Yarn or PNPM. Node.js recognizes in package.json which package manager is defined - a huge relief that is built in from version 16.9.0. It's an experimental feature, but it's easy to run. I would also add that writing is longer with CorePack. Instead of writing “yarn add foo,” it’s necessary to add “corepack yarn add foo” to the beginning, although it can be shortened by aliases in some cases.

Is there a winner?

Let's sum it up. NPM is slower, but its creators are trying to improve it and it is catching up to the competition, but sequential downloads remain a core problem.

PNPM and Yarn PnP are fast, but their implementation can be problematic at times. I think Yarn is still “in,” and so far I haven't encountered any major problems using it.

And what about you? Which package manager wins for you? Let me know at tomas.veprek[at]cookielab.io.

Package Managers Comparison: Yarn, NPM, PNPM | Cookielab (2024)

FAQs

Is Pnpm better than Yarn? ›

Pnpm Performance and Disk Efficiency

Yarn uses the same flattened node_modules directory but is comparable to NPM in speed and installs packages parallelly. On the other hand, PNPM is 3 times faster and more efficient than NPM. With both cold and hot cache, PNPM is faster than Yarn.

Which package manager is best, npm or Yarn? ›

B. Yarn vs NPM: Performance and Speed
YarnNPM
It is faster when installing large files.It is slower when installing large files.
It supports Zero-Install feature that allows you to install dependencies offline with almost no latency.It doesn't support any such feature.
1 more row
May 22, 2024

What are the downsides of Pnpm? ›

Disadvantages of pnpm:

Compatibility Problems: Because of its distinct approach to package management, pnpm may cause compatibility problems in certain projects, especially those that are not specifically made for it.

Is bun faster than pnpm? ›

When writing files from the cache into node_modules , Bun uses the fastest system calls available on your operating system. This is dramatically faster than naively symlinking from a global cache like pnpm .

Should I use pnpm in production? ›

Advantages of pnpm​

As shown in the previous section, pnpm uses a content-addressable file system to store the packages and dependencies on the disk. That means the same package will not be duplicated. Even with different versions of the same package, pnpm is intelligent enough to reuse the maximum code.

Does pnpm replace Yarn? ›

Pnpm is more strict than Yarn when dealing with dependencies. This is a good thing, because it makes package configurations self-sufficient. However, migrating from yarn to pnpm, you may find that you miss some dependencies in your packages for this reason.

Why is PNPM faster than npm? ›

As you can see, PNPM is the fastest package manager, followed by YARN and then NPM. This is because PNPM uses a novel approach called “symlinked node_modules”, which creates hard links to the global store of packages instead of copying them to each project. This saves disk space and reduces duplication.

Why people prefer Yarn over npm? ›

It was created to address the shortcomings of older versions of the NPM CLI and it quickly garnered attention and support from a large open-source community. Today, Yarn is a popular alternative to npm because it's fast and easy to use.

What is the fastest npm package manager? ›

Advantages and disadvantages of PNPM (Performant NPM)

PNPM is the newest and fastest package manager. It works quite similarly to Yarn's PnP in that it also uses symlinks.

What is the drawback of pnpm? ›

Another nice feature is that when you use PNPM it will tell you in the console how many packages you're reusing and how much disk space you've saved, so if recycling is your thing, you'll like this feature. PNPM has the same drawback as PnP — namely that it may not support all packages.

Can I use npm and pnpm together? ›

I would not recommend mixing pnpm and npm. pnpm uses its own lock file. There's no guarantee your app/library will be using the exact package versions everyone else is using. That leads to it-works-on-my-machine kind of bugs.

Should you use Yarn PnP? ›

Because Yarn keeps a list of all packages and their dependencies, it can prevent accesses to dependencies unaccounted for during resolution, giving you the ability to quickly identify and fix those problems before they get deep into your codebase and jeopardize the stability of your application at deploy time.

Is PNPM vs npm in 2024? ›

In 2024, PNPM, NPM, and Yarn continue to evolve. PNPM focuses on speed and efficiency, NPM remains committed to enhancing security and performance, and Yarn pushes the boundaries of innovation with updates to Plug'n'Play (PnP) and workspace management.

Why using PNPM? ›

Advantages of Using PNPM

Reduced Disk Space Usage By storing packages in a global store and linking them, PNPM minimizes the disk space required for dependencies. This is particularly advantageous for developers working on multiple projects on the same machine.

Is bun ready for production? ›

In 2023, the JavaScript world, particularly its backend sector, was shaken by the news of the production-ready release of Bun. Positioned as a prospective rival to Node. js, Bun introduced a new development environment, sparking considerable discussion within the community.

Why should I use pnpm? ›

PNPM: Utilizes a shared dependency mechanism that allows different projects to use the same copy of a package. This efficient approach minimizes duplication and reduces disk space usage.

Should you use yarn PNP? ›

Because Yarn keeps a list of all packages and their dependencies, it can prevent accesses to dependencies unaccounted for during resolution, giving you the ability to quickly identify and fix those problems before they get deep into your codebase and jeopardize the stability of your application at deploy time.

Does it matter if I use yarn or npm? ›

NPM vs Yarn: the Difference

Yarn has a few differences from npm. First of all, Yarn caches all installed packages. Yarn is installing the packages simultaneously, and that is why Yarn is faster than NPM. They both download packages from npm repository.

How is pnpm faster? ›

But if you observe last line in output - progress: it has reused 18 packages already installed for application1. “In pnpm, packages are always reused if they are already installed for another project saving a lot of disk space which makes it faster and more efficient than npm.”

Top Articles
Braiins Pool | Help Center
Walk On Glass, Glass Floor & Structural Glass Floor Panels
Roblox Roguelike
Winston Salem Nc Craigslist
Wellcare Dual Align 129 (HMO D-SNP) - Hearing Aid Benefits | FreeHearingTest.org
Google Sites Classroom 6X
Konkurrenz für Kioske: 7-Eleven will Minisupermärkte in Deutschland etablieren
Tabler Oklahoma
Prices Way Too High Crossword Clue
Cape Cod | P Town beach
World Cup Soccer Wiki
Revitalising marine ecosystems: D-Shape’s innovative 3D-printed reef restoration solution - StartmeupHK
Voyeuragency
Local Dog Boarding Kennels Near Me
Eka Vore Portal
National Office Liquidators Llc
Grab this ice cream maker while it's discounted in Walmart's sale | Digital Trends
Puretalkusa.com/Amac
Alexander Funeral Home Gallatin Obituaries
Loves Employee Pay Stub
Officialmilarosee
Wbiw Weather Watchers
Xfinity Cup Race Today
Johnnie Walker Double Black Costco
Surplus property Definition: 397 Samples | Law Insider
Defending The Broken Isles
Best Town Hall 11
CohhCarnage - Twitch Streamer Profile & Bio - TopTwitchStreamers
My Reading Manga Gay
Little Einsteins Transcript
Shaman's Path Puzzle
Lil Durk's Brother DThang Killed in Harvey, Illinois, ME Confirms
Σινεμά - Τι Ταινίες Παίζουν οι Κινηματογράφοι Σήμερα - Πρόγραμμα 2024 | iathens.gr
Cruise Ships Archives
Sinai Sdn 2023
Case Funeral Home Obituaries
Tokyo Spa Memphis Reviews
Nba Props Covers
Craigslist Pets Plattsburgh Ny
Janaki Kalaganaledu Serial Today Episode Written Update
Pokemon Reborn Gyms
Sound Of Freedom Showtimes Near Lewisburg Cinema 8
Traumasoft Butler
Craigslist Malone New York
Gabrielle Abbate Obituary
The Average Amount of Calories in a Poke Bowl | Grubby's Poke
Dragon Ball Super Card Game Announces Next Set: Realm Of The Gods
Union Supply Direct Wisconsin
Nurses May Be Entitled to Overtime Despite Yearly Salary
Mail2World Sign Up
Diario Las Americas Rentas Hialeah
Unbiased Thrive Cat Food Review In 2024 - Cats.com
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6281

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.