When multiple Git branches modify the dependencies in a project that uses Yarn, it is likely to introduce a conflict in the yarn.lock file. It is not a good idea to delete and regenerate the yarn.lock file because this will probably cause several packages to be unintentionally upgraded. What is the best way to quickly resolve conflicts in this file?
4 Answers
Since Yarn 1.0 it's easy because it has built in support for this scenario.
First solve the conflict in package.json
manually, then just run this:
$ yarn install
yarn install v1.0.1
info Merge conflict detected in yarn.lock and successfully merged.
[1/4] Resolving packages...
And then the conflict will be resolved and you can commit that or continue rebasing if that was what you were doing.
-
1I don't believe this works if there are conflicts in your
yarn.lock
containing lines of code such as============
,>>>>>>>>>>>>>>
,<<<<<<<<<<<<<
. You still need to do what Christine Schlensker's answer talks about. Oct 4, 2017 at 21:23 -
93
-
19you need to fix your conflicts in package.json first then run yarn and it should handle it– belgacOct 11, 2018 at 11:44
-
5It printed out the "successfully merged" message for me but the yarn.lock still contained the merge conflicts.– sliktsNov 5, 2020 at 9:33
-
4
A good approach is detailed in this github discussion about the issue.
git rebase origin/master
When the first conflict arises, I checkout the
yarn.lock
then re-perform the installationgit checkout origin/master -- yarn.lock yarn install
This generates a new
yarn.lock
based on the origin/master version of yarn.lock, but including the changes I made to mypackage.json
. Then it's just a matter of:git add yarn.lock git rebase --continue
-
For this and the accepted answer, I have to repeat the commands multiple times and git ends up with the following:
No changes - did you forget to use 'git add'? If there is nothing left to stage, chances are that something else already introduced the same changes; you might want to skip this patch.
– ADPJun 1, 2020 at 12:09 -
My fix ended being these steps on a regular merge - It never worked on my rebase.– ADPJun 1, 2020 at 16:03
If ‘yarn install’ doesn’t helped
1) git checkout <target branch>
2) git pull
3) git checkout <our branch with conflict>
4) git merge <target branch> (you will see merge conflict on yarn.lock)
5) rm yarn.lock
6) yarn
7) git add yarn.lock
8) git commit -m
9) git push
this file is too long so if you need to check conflict in vscode without terminal maybe you can try a search in this file for terms like: >>>>>>>
, =======
, <<<<<<<
or HEAD