Passer au contenu principal
Version : 7.x

pnpm vs npm

Structure flat de npm

npm maintient une arborescence de dépendances aplaties depuis la version 3. Cela mène a une réduction d'espace disque, avec un répertoire node_modules désordonné comme effet secondaire.

D'un autre côté, pnpm gère les node_modules en utilisant un lien fixe et un lien symbolique vers un magasin global adressable au contenu sur le disque. Cela vous apporte les avantages d'une utilisation moins gourmande en espace disque, tout en gardant les node_modules propres. Il y a une documentation sur l'agencement du magasin si vous voulez en savoir plus.

The good thing about pnpm's proper node_modules structure is that it "helps to avoid silly bugs" by making it impossible to use modules that are not specified in the project's package.json.

Installation

pnpm does not allow installation of packages without saving them to package.json. If no parameters are passed to pnpm add, packages are saved as regular dependencies. Like with npm, --save-dev and --save-optional can be used to install packages as dev or optional dependencies.

As a consequence of this limitation, projects won't have any extraneous packages when they use pnpm unless they remove a dependency and leave it orphaned. That's why pnpm's implementation of the prune command does not allow you to specify packages to prune - it ALWAYS removes all extraneous and orphaned packages.

Directory dependencies

Directory dependencies start with the file: prefix and point to a directory in the filesystem. Like npm, pnpm symlinks those dependencies. Unlike npm, pnpm does not perform installation for the file dependencies.

This means that if you have a package called foo (<root>/foo) that has bar@file:../bar as a dependency, pnpm won't perform installation for <root>/bar when you run pnpm install on foo.

If you need to run installations in several packages at the same time, for instance in the case of a monorepo, you should look at the documentation for pnpm -r.