How to Find and Delete Old node_modules Folders on a Mac
Yes—you can safely delete node_modules folders in inactive projects on macOS. Every package inside node_modules can be reinstalled later with npm install , yarn , pnpm install , or bun install as long as your package.json and lockfile are intact. If you build side projects or use AI coding tools like Claude Code, Cursor, or Codex, node_modules folders pile up quickly across dozens of folders and…
To safely remove outdated node_modules folders from a Mac, first determine how much space they occupy. Using the command "find ~ (-path ~/Library -o -path ~/.Trash -o -name .git) -prune -o -type d -name node_modules -prune -exec du -sh {} +" will list the largest top-level node_modules directories in your home folder. This should be run with caution, as it could accidentally delete important directories if not used correctly.
Next, identify which projects are safe to clean. Any project with a node_modules folder not modified in the last 60 days can be considered safe for deletion. Running the command "find ~/Projects -name node_modules -type d -prune -mtime +60 -exec du -sh {} +" will show the size of each project's node_modules folder. Again, this should only be done after confirming that the project is not currently in use.
Node_modules should not be deleted in active projects or projects that track dependencies in Git. Projects using pnpm may also require special attention, as they use a shared store to minimize duplication. In these cases, running "pnpm store prune" can help reclaim space.
When deleting node_modules, it's best to use the "rm -rf" command to move the folder to the Trash rather than deleting it permanently. This allows for easy recovery if needed. Alternatively, npm kill can be used to interactively delete dependencies from a specific project.
After deleting node_modules, it's necessary to re-install project dependencies using the appropriate npm, yarn, pnpm, or bun command. This ensures that all required packages are restored to their latest versions.
While deleting node_modules can free up significant disk space, the immediate impact may not be noticeable. This is often due to space being temporarily reserved in the Trash or due to specific behaviors of package managers like pnpm. Therefore, it's important to manage expectations and allow some time for the space to be reclaimed.
In summary, deleting old node_modules folders on a Mac is a safe and effective way to reclaim disk space, provided that the projects are not currently in use and the package.json and lockfiles are intact. Always exercise caution when running cleanup commands and verify that the necessary dependencies will be re-installed before proceeding.
Rewritten by urgent.news; may contain errors — check the original.