Npm Install Drives You Crazy? Yarn And Chill!

If you ever dealt with npm install in continuous integration environment, you know the pain. Facebook just introduced Yarn. When I tried it, it was "un coup de foudre" (love at first sight). Let me tell you why.

Disclaimer: Remember that there is nothing like silver bullet. Yarn is still pre-release software so it might not yield great results for you.

Npm install is so slow

Our first and main struggle is time, this is the one and only thing we cannot extend. Money, we can always find some, but time...

We are currently building and maintaining various Cordova apps for a big customer. In that process, we build apps across various environments (continuous, validation, preproduction, earlypreview, production).

While some power-users can have the five app versions installed, product owners have two or three installed. To get this done, we extensively rely on Team Services and Hockey App and this is working pretty well.

Except for one thing! It takes us something like 25 minutes to get a master build done. In that process, npm install takes 16 minutes alone. Why is it that bad?

The root cause is that npm, node and javascript motto of single responsibility principle leads to dependency hell and spaghetti effect. LeftPad showed us how bad it can be. The thing is that those tools are what they are, so that's it! We have to deal with those 910 dependencies...

But that being said, what makes it that slow? Downloading 910 small tarballs shouldn't take so much time, should it? Absolutely not, but:

Npm caches nothing

Dependencies are listed in the tarball

npm is not very good at parallelisation

npm is not very resilient when it comes to transient failures

We tried different approaches using various tools you can find about on google, but they led to nothing good. So, we just sucked it up!

npm install, this things we have to play around but which sometimes scares us.

Kitty Kitty ! Come back ! Here is Yarn.

Yarn is the ultra fast, mega secure and super reliablepackage manager. I first said : Meh, yet another buggy, overly complicated, half of a solution.

Then I saw the getting started and realized it was even more simple:

npm install becomes yarn

npm install --production becomes yarn --prod

npm install lodash --save becomes yarn add lodash

npm install webpack --save-dev becomes yarn add webpack --dev

This is almost a drop in replacement with a better, slicker syntax.

So I said: why not give it a try, even Node.JS think it's great. So we did it and here are the results:

npm install : 4.1 minutes per run

yarn : 2 minutes for the first run and 1 minute for subsequent runs

To us, this is already really huge! Besides, there a few features like mixed sources and licences check which will be extremely helpful.

Limitations we've encountered so far

We'd like to friendly remind you that's despite it's being used in production at Facebook, Yarn is still pre-release software. So glitches are to be expected :).