简体   繁体   中英

Why is my node_modules folder full of so many files I have not installed?

I'm creating a nodeJS application and struggling to upload it onto my server. I only have 6 dependencies yet for some reason my node_modules folder has 119 folder in it. Do I need the ones that I have not installed or have in my dependencies in my pack.json?

Thanks in advance!

Node.js is all about modularity, and with that comes the need for a quality package manager; for this purpose, npm was made. With npm comes the largest selection of community-created packages of any programming ecosystem, which makes building Node.js apps quick and easy

  • How dependencies are managed

Each library / dependency you add to your project must have a semantic version as 1.2.x and can either has other dependencies used in it or none.

So if each dependency you added to your project has its own dependencies with different versions this will make the package manager you are using add them to node_modules

Project dependencies with dependencies that are common and have no breaking API / semantic version are bubbled up to your node_modules directory and the rest of dependencies versions which aren't common live in their own node_modules directory in the libraries you added to your project

This is a general idea of how dependencies are managed and the reason for Node.js modularity.

There are also downsides to this workflow as said by Ryan Dahl the original developer of Node.js, because node_modules directory becomes bloated.

You should listen to one of his talks 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU

The dependencies you've installed are reliant on other dependencies, just like your code is dependent on the ones you've installed.

That is why there are so many other folders.

You can see a list of all the other dependencies on which the library you installed is dependent, by running:

npm view (package name) dependencies

For visual learners, this concept is well demonstrated in this portion of this video .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM