Yarn & Plug'n'Play (PnP / Zero Installs)
Discover how Yarn PnP uses a generated dependency loader instead of the usual node_modules lookup, and how a configured project cache supports zero-installs workflows.
What is Yarn Plug'n'Play (PnP)?
Yarn Plug'n'Play (PnP) is an alternative module resolution strategy introduced in Yarn Berry (v2+) that completely eliminates the node_modules folder from Node.js projects.
PnP generates a loader named .pnp.cjs with dependency locations and relationships. Package archives can be reused from Yarn's cache; a project-local .yarn/cache is a configuration choice rather than the universal default.
Why eliminate node_modules and move to Zero Installs?
Traditional node_modules folders create massive overhead: disk operations (thousands of fs.stat calls) slow down application startup, file copying during installs takes minutes, and flat hoisting introduces dangerous phantom dependencies.
A zero-installs workflow combines PnP with a committed project-local cache and loader data. This can avoid repeated fetching or linking after checkout, but does not eliminate compilation, native-package setup or every environment-specific step.
How Yarn PnP Resolves Packages at Runtime
Yarn configures its generated PnP loader so Node and supported tools can resolve declared packages using the dependency map and cache locations.
When code loads a package, PnP resolves it using the importing package's dependency relationships. It can report undeclared dependencies instead of relying on an incidental hoisted node_modules layout.
Inspect Yarn PnP and Test In-Memory Resolution
Experience how Yarn PnP resolves dependencies directly from zip archives without a node_modules folder.
Step through Yarn PnP architecture to compare node_modules vs .pnp.cjs resolution
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- PnP uses a generated .pnp.cjs dependency loader instead of conventional node_modules traversal.
- Zero-installs requires a deliberate committed-cache workflow; native setup or builds may still be needed.
- PnP prevents phantom dependencies by strictly enforcing declared dependencies in
package.jsonat resolution time. - Use supported editor integration and yarn node to run Node with the project's PnP hook.
Done with this concept?
Mark it complete to track your progress. No login needed.