Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I commit the yarn.lock file and what is it for?

Tags:

yarnpkg

Yarn creates a yarn.lock file after you perform a yarn install.

Should this be committed to the repository or ignored? What is it for?

like image 308
rlay3 Avatar asked Oct 12 '16 03:10

rlay3


People also ask

What is the purpose of yarn lock file?

When present in the project, yarn. lock is the main source of information about the current versions of dependencies in a project. Yarn uses that information to check if it needs to update anything – it compares dependency versions currently installed in a project (listed in yarn.

Should you commit yarn lock json?

It is highly recommended you commit the generated package lock to source control: this will allow anyone else on your team, your deployments, your CI/continuous integration, and anyone else who runs npm install in your package source to get the exact same dependency tree that you were developing on.

Should I use yarn lock?

From My experience I would say yes we should commit yarn. lock file. It will ensure that, when other people use your project they will get the same dependencies as your project expected. When you run either yarn or yarn add , Yarn will generate a yarn.

Should I git ignore yarn lock?

You should never, ever "gitignore" your lock files( package-lock. json and/or yarn. lock )! Even when installing using npm install , it generates a notice that we "should commit this file".


2 Answers

Yes, you should check it in, see Migrating from npm

Why is it for?
The npm client installs dependencies into the node_modules directory non-deterministically. This means that based on the order dependencies are installed, the structure of a node_modules directory could be different from one person to another. These differences can cause works on my machine bugs that take a long time to hunt down.

Yarn resolves these issues around versioning and non-determinism by using lock files and an install algorithm that is deterministic and reliable. These lock files lock the installed dependencies to a specific version and ensure that every install results in the exact same file structure in node_modules across all machines.

like image 194
ckuijjer Avatar answered Sep 25 '22 03:09

ckuijjer


Depends on what your project is:

  1. Is your project an application? Then: Yes
  2. Is your project a library? If so: No

A more elaborate description of this can be found in this GitHub issue where one of the creators of Yarn eg. says:

The package.json describes the intended versions desired by the original author, while yarn.lock describes the last-known-good configuration for a given application.

Only the yarn.lock-file of the top level project will be used. So unless ones project will be used standalone and not be installed into another project, then there's no use in committing any yarn.lock-file – instead it will always be up to the package.json-file to convey what versions of dependencies the project expects then.

like image 31
VoxPelli Avatar answered Sep 24 '22 03:09

VoxPelli