Why use Yarn over NPM? The brilliant yarn.lock file

Regev Golan
2 min readMay 1, 2017

--

yarn logo from https://yarnpkg.com

Yarn is the new Javascript package manager in town, created by Facebook, and it is so cool, useful and easy to adopt, that NPM may soon become obsolete. In this short example I’ll try to clarify this key killer feature of Yarn, that is the hardest one to understand: The yarn.lock file.

Let’s say Alice did a small change in the package.json of our project and committed it to master.

Bob pulled locally, and did a `yarn install` but then his git showed uncommitted differences on the yarn.lock file even though Bob didn’t changed anything. Why?

yarn.lock file actually warned us that something is not right by showing the uncommitted changes. Alice touched the package.json but didn’t actually re-run the `yarn install` creating a “non synced” package.json and yarn.lock. This is exactly the big value of yarn over npm because Alice “caused” a situation in which our web-service is going to be different than what Alice have locally, which is a bad thing and can cause “but it worked on my environment” problems.

With the lock file, yarn shows the power of another layer of validation between environments.

See great further reading on this amazing package manager from https://yarnpkg.com/

Last point I want to share from my experience is that migrating all of our production services and development environments from npm to Yarn went very smoothly and easily.

Goodluck!

Regev Golan

--

--