On paper, Yarn and NPM 5 look almost equivalent. They both have deterministic lock files and have almost matched each other in functionality. Some would say that Yarn was the catalyst to get NPM innovating.
However, after experiencing NPM 5 for a month, my team decided to move to Yarn.
NPM technically has a "more deterministic" lock file in that there is a theoretical guarantee that across NPM versions, NPM will produce the exact same node_modules
folder. On the other hand, Yarn's exact hoisting/ordering of dependencies depends on the Yarn version and could change across Yarn versions. In general, this has very little impact.
Why use Yarn then? Merging & reliability.
Yarn made the slight determinism trade-off to achieve a much simpler yarn.lock
file that is easier to merge. If you are a solo-developer, this probably will not impact you, but if you are on a team with multiple collaborators committing dependency changes, it quickly becomes a huge problem. NPM's package-lock
is practically un-mergeable and you end up having to re-generate or struggle. On the other hand, with Yarn, merges are easy and predictable.
See: https://yarnpkg.com/blog/2017/05/31/determinism/
As a side note, we also found Yarn to be more reliable on average.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…