This is a very good question, there are a few things I want to point out.
V8 engine, Node Modules (dependencies) and require them
Node.JS is built on a V8 engine, the source code of which is C ++. This means that Node.JS dependencies are based on C ++.
Now that you require you to change the dependency, you are actually removing the code / functions from the C ++ program. How libraries / dependencies are created.
There are many functions in libraries that you will not use
For example, see the express validation module . There are so many functions. When you need a module, do you use all the functions it provides? The answer is no . People need such packages to take advantage of only one advantage, and all functions end up loading, which takes up unnecessary space.
Think of Node dependencies that are made from other Node dependencies as interpreted languages
Example: Javascript is written in C / C ++, these languages ββare written in assembly. Think of it as a tree. Each time you create new branches for more convenient use and, most importantly, to save time. This speeds up the work. This is a similar situation for creating new dependencies, when people create a new dependency that is require those that already exist, instead of writing an entire C ++ program, because it makes everything simpler.
The problem arises when other NPMs are required to create a new
When dependency authors require other dependencies on here and there only to take advantage of a few (small) advantages from them, they end up loading them all (which they don't care because they prefer to do this than write a new add-on in C ++ explicitly ), and this takes up additional space. For example, you can see the dependencies that the express-validator module uses from from this link.
So, when you have large projects that use many dependencies, you end up taking up so much space for them.
Ways to solve this problem
Number 1
- This requires some experts from Node.JS. To reduce the number of downloaded packages, a professional Node.JS developer could go to the directories in which the modules are stored, open the javascript files, see their source code and remove functions that they will not use without changing the structure of the package.
Number 2 (which is almost impossible)
- You can also create your own personal dependencies written in C ++ that literally take up the least space, but will take up the most time. I do not recommend doing this at all! You need C ++ specialists for this purpose.
Conclusion && Note
So basically there is no way to drop all Node packages, but you can use solution number 1 if you think you can do it, or force someone else to process it. I still think this is not a good idea.
Also, ask yourself this question, do these packages really cause a problem?