I have multiple projects with a lot of similar dependencies that end up in the node_modules folder. These duplicates can add up both in size and unnecessary downloads. Is there a way to improve this situation?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (3)
As for the downloads, I think there's already npm local cache handling this.
And I am not sure if I understand correctly what you want to achieve, but you can create and intermediate dependency that would aggregate common libraries and then use its build output in your other projects. Maybe it would be a good use case to define the "vendor.js/css" files.
Something like
Specific project -> Common Module -> [vendor1, vendor2,...]
The short answer is that there is no way to handle similar dependencies over multiple projects. Nor should there be. NPM is designed to be a project package manager. Not a system package manager.
Out of curiosity, what is the drive to combine similar project dependencies?
Thank you for your answer. I fully understand that a project is designed to contain all its dependencies in npm and should do so in production state. However, I would like to be able to do this in a local environment.
The drive is simply for disk space and install speed.
I have a small SSD that I use for development mainly because I am on a budget but want speed. Logically it seems unnecessary to have multiple copies of dependencies on the same machine to run a npm package, and I was thinking maybe there is a solution to easily cache common dependencies in a system wide cache folder.