pnpm - Do node_modules directories occupy the same space in disk?
Asked Answered
S

1

6

I have multiple Vue.js projects spread across my laptop's file system. I have searched and found a solution to the npm node_modules folder size problem with pnpm. After installing the projects dependencies with pnpm i, the size of the node_modules folder still says that it occupies 233 MB of space in each project. I was simply wondering if all of these project's node_modules folders are using the same 233 MB of hard disk space assuming that all projects have the same dependencies.

Sortie answered 7/3, 2019 at 2:12 Comment(1)
To calculate the size of a directory ignoring hard links run du -sh node_modules node_modules. The second line in the output is the size of the directory disregarding hard links. du counts only the first of all hardlinks pointing to the same inode it encounters.Sibilate
W
8

Yes, all of those project's node_modules use the same 233 MB of disk space.

From the FAQ page of pnpm website:

Why does my node_modules folder use disk space if packages are stored in a global store?

pnpm creates hard links from the global store to project's node_modules folders. Hard links point to the same place on the disk where the original files are. So, for example, if you have foo in your project as a dependency and it occupies 1MB of space, then it will look like it occupies 1MB of space in the project's node_modules folder and the same amount of space in the global store. However, that 1MB is the same space on the disk addressed from two different locations. So in total foo occupies 1MB, not 2MB.

For more on this subject:

Wicker answered 7/3, 2019 at 9:36 Comment(1)
The pnpm FAQ page link is now broken, new link is pnpm.io/en/…Finn

© 2022 - 2024 — McMap. All rights reserved.