JavaScript, dependencies and complexity
June 21, 2019
A few thoughts about the excessive amount of dependencies that each JavaScript library/framework seems to have and some comparisons.
I was doing some Exercism.io problems the other day and out of curiosity I started to wonder how the same exercise in JavaScript would compare to a couple of other languages, so I picked the first exercise in each track, which is a very simple ”Hello World!” string being returned by a function and a test case for this, keep in mind this is just the first exercise to check you have all the tooling working and familiarize yourself with the platform, is very simple, so, how complex could it be? right?
1. Golang
Runs the test case in 0.2-0.3 seconds:
Weights 8 KB, has 4 files, 1 folder.
Simple, right?
2. C#
Runs the text case in 1.1-1.2 seconds:
Weights 984 KB, has 27 files, 7 folders.
1.2 seconds to run such a simple test case and function seems way too much, anyway, bearable, I guess…
3. Node.js
Takes around 7 seconds to run the first time, runs at about 1.6-2 seconds subsequently:
Weights 74.8 MB, has 14604 files, 1690 folders.
75 MB and more than 14k files to run (poorly) a test case and an oneline function. You may argue that the other examples didn’t include some stuff like the testing framework itself, and you’d be right, but consider that the whole source code for xUnit (C#) is 4MB and 700 files, so I don’t think it would make much of a difference.
Taking a look inside the node_modules its an adventure in its own, maybe a blogpost for another day.
I won’t lie, it worries me that we are willing to put up with such amounts of unecessary dependencies and complexity, but it worries me even more that we have normalized this situation. We have started to suffer from this dependency hell, with packages trying to steal credentials or even bitcoins, getting more common each time.