Node.js linkers
Yarn supports three different ways to install your projects on disk. This document gives a quick overview of each of them, along with the pros and cons of each.
nodeLinker: pnp
For more details about Plug’n’Play installs, check the dedicated section.
Under this mode Yarn will generate a single Node.js loader file directory referencing your packages from their cache location. No need for file copies, or even symlinks / hardlinks.
| Pros | Cons |
|---|---|
| Extremely fast | Less idiomatic |
| Content-addressable store | IDE integrations often require SDKs |
| Protects against ghost dependencies | Sometimes requires packageExtensions |
| Semantic dependency errors | |
| Perfect hoisting optimizations | |
| Provides a dependency tree API | |
| Can be upgraded into zero-installs |
nodeLinker: pnpm
Section titled “”Under this mode, a flat folder is generated in node_modules/.pnpm containing one folder for each dependency in the project. Each dependency folder is populated with hardlinks obtained from a central store common to all projects on the system (by default $HOME/.yarn/berry/index). Finally, symlinks to the relevant folders from the flat store are placed into the node_modules folders.
| Pros | Cons |
|---|---|
| Slower than PnP, but still very fast | Symlinks aren’t always supported by tools |
| Content-addressable store | Hard links can lead to strange behaviors |
| Protects against some ghost dependencies | Generic dependency errors |
| No need for IDE SDKs | Sometimes requires packageExtensions |
nodeLinker: node-modules
Section titled “”This mode is the old tried and true way to install Node.js projects, supported natively by Node.js and virtually the entirety of the JavaScript ecosystem.
While we tend to recommend trying one of the two other modes first, it remains a solid option in case you face problems with your dependencies that you don’t have the time to address right now. Sure, your project may be a little more unstable as you won’t notice if ghost dependencies creep in, but it may be a reasonable trade-off depending on the circumstances.
| Pros | Cons |
|---|---|
| Perfect compatibility with the whole ecosystem | Average speed |
Optional support for hardlinks (nmMode) | No protection against ghost dependencies |
| No need for IDE SDKs | Imperfect hoisting due to the filesystem reliance |