rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

[RRFC] node_modules using high disk space

Open brillaintlcd opened this issue 5 years ago • 1 comments

Motivation ("The Why")

The node_modules is consuming a large disk space. So,. It would be better if it installs the packages in the root of the user in the computer. In windows the path would look like: C:\Users\user_name\node_modules. Users could install the different versions of a package. And it would import packages matching the version inside the package.json. Python packages📦 use this kind of concept and it consumes less storage.It only does one installation.And we don't neee to install it again.

Example

Using less storage space. Avoiding the large node_modules folder in every single project. Just one node_modules in the root of the user. Users could install the different versions of a package. And it would import packages matching the version inside the package.json.

How

Current Behaviour

Currently npm does install the whole project packages in the project folder📁.This takes up the storage of the system.I know we can import packages from the root folder. But, this kinda idea should be the only way to import packages 📦. As it increases perfomance.

Desired Behaviour

When we run npm install it should only install in the root user folder.

References

  • n/a

brillaintlcd avatar Jul 03 '21 04:07 brillaintlcd

The node_modules disk space problem is real I work on 15+ Node projects and a quick audit showed 40+ GB across all node_modules directories:

# Find how much space node_modules uses across all projects
find ~/Developer -name "node_modules" -type d -maxdepth 4 2>/dev/null | while read d; do
  du -sh "$d" 2>/dev/null
done | sort -rh | head -20

Some practical approaches that help:

1. Use a space-efficient package manager

  • pnpm uses a content-addressable store + hard links, so packages are stored once. Can save 50-70% disk space vs npm.
  • bun install is also more efficient with caching.

2. Clean stale node_modules

# Remove node_modules from projects not touched in 30+ days
find ~/Developer -name "node_modules" -type d -maxdepth 3 \
  -exec sh -c 'if [ $(find "$1/.." -maxdepth 1 -mtime -30 | head -1 | wc -l) -eq 0 ]; then echo "Removing $1"; rm -rf "$1"; fi' _ {} \;

3. Clean package manager caches

npm cache clean --force     # ~/.npm/_cacache
yarn cache clean            # ~/Library/Caches/yarn
pnpm store prune            # ~/Library/pnpm/store

For keeping tabs on all of this automatically, I maintain ClearDisk it's a free macOS menu bar app that monitors npm/yarn/pnpm caches, node_modules, and 40+ other developer cache paths in one place.

bysiber avatar Mar 05 '26 01:03 bysiber