NPM Vs Yarn 2019

New year, old package management

Recently my team has been running into a an odd bug in development:

Image for post
Image for post

You can read the actual Github issue I created: https://github.com/palantir/blueprint/issues/3254

This error would constantly be appearing whenever this component calling this function would get mounted. Turns out that we had a conflicting, nested version of React installed inside of our node_modules. So how did this happen? After some research it seems that this conflicting version of React would only get installed when running yarn install. Deleting my node_modules and running npm install reliably installed my dependencies correctly causing this error to disappear. With this new discovery I’m compelled to make my team switch over from using Yarn to NPM. This has lead me to research more about the differences between these two package management systems.

When looking at this problem it’s good to look back and understand what made Yarn an attractive alternative to begin with. I’ve narrowed it down to two big reasons. Speed and the auto-generated lock file. Let’s talk about the more complicated of the two; yarn.lock

What is the lock file

The lock file will literally “lock” the installed dependencies’ version. The first time you run yarn it will auto generate a yarn.lock file for you. This lock file will record each of the installed dependencies version’s into it. So when your coworker pulls the remote and runs yarn he’s guaranteed to have the same versions of the packages that you are using.

This innovation was very attractive and was one less thing developers had to worry about. However, as of NPM v5.0.0, NPM will auto generate it’s own lock file which does the same thing. Yarn did it first, but that’s hardly an “advantage” over NPM today.

Speed

The Conclusion

Note: If you want an in depth explanation of how NPM and package management works, check out this great article by Alexis King

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store