New users of pnpm frequently ask me about the weird structure of node_modules
that pnpm creates. Why is it not flat? Where are all the sub-dependencies?
I am going to assume that readers of the article are already familiar with flat
node_modules
created by npm and Yarn. If you don't understand why npm 3 had to start using flatnode_modules
in v3, you can find some prehistory in Why should we use pnpm?.
So why is pnpm's node_modules
unusual? Let's create two directories and run npm add express
in one of them and pnpm add express
in the other one. Here's the top of what you get in the first directory's node_modules
:
.bin
accepts
array-flatten
body-parser
bytes
content-disposition
cookie-signature
cookie
debug
depd
destroy
ee-first
encodeurl
escape-html
etag
express
You can see the whole directory here.
And this is what you get in the node_modules
created by pnpm:
.pnpm
.modules.yaml
express