Yarn: Deal with lockfile merge conflicts in some way

Created on 5 Dec 2016  路  11Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
So I just had to merge two branches that had diverged a bit in package.json but a whole lot in the lockfile, causing 93 merge conflicted according to my mergetool. One branch had removed some dependencies, the other had upgraded some. For some of these conflicts I had no idea which version to pick, and I had to throw away the lockfile, defeating the purpose of having a lockfile.

What is the expected behavior?
I am unsure how Yarn should handle this. I don't expect it to include a mergetool, but right now merging the lockfile is not really doable, leading to people putting the lockfile in gitignore as seen here https://github.com/yarnpkg/yarn/issues/1776#issuecomment-264209697.

Most helpful comment

@tricoder42 in case you haven't seen it already, that feature has been included in the 1.0.0 release that happened yesterday. Update Yarn and running yarn install should fix the conflicts for you.
I just tried and worked like charm!

All 11 comments

I hate this
rm yarn.lock && yarn && git add yarn.lock && git rebase --continue

This appears to be a recipe and could be scripted I believe

https://github.com/yarnpkg/yarn/issues/1776#issuecomment-269539948

I have a proposal: yarn install could detect for common merge-conflict markers (i.e. <<<<<<< for git) and give a hint!

@neiker command is what I do now, but it has a problem: it updates all packages minor version, and this is not what yarn wants.

the cited @IanVS solution is IMHO the best one, but I don't know if it could be scripted @wizardzloy, too many different platforms, problems, etc.
But it could be yarn's hint to resolve the conflict.

@caesarsol yes, I have all my dependencies fixed, but my dependencies dependencies aren't. So it's a problem. @IanVS solution is the best at the moment.

Maybe, mark it as binary in gitattributes? This will make git ignore conflicts and line endings, like if file was binary. Just create .gitattributes file in root and add yarn.lock binary to it.

@adrienko that is a pretty smart and clean idea! does it work smoothly even in rebase cases?

@caesarsol commit the .gitattributes once. After that, you're home free. Works.

Hello,
https://github.com/yarnpkg/yarn/pull/3544 seems to be merged, but it doesn't seem to work. First I resolved conflicts in package.json.

Then I run run to resolve merge conflicts in yarn.lock:

snimek obrazovky 2017-09-06 v 15 34 56

but yarn fails with error:

error An unexpected error occurred: "Unknown token 1876:1

Line 1876 is the merge conflict:

<<<<<<< HEAD
[email protected], create-react-class@^15.5.2, create-react-class@^15.5.x, create-react-class@^15.6.0:
  version "15.6.0"
  resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.0.tgz#ab448497c26566e1e29413e883207d57cfe7bed4"
=======
create-react-class@^15.5.1, create-react-class@^15.6.0:
  version "15.6.0"
  resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.0.tgz#ab448497c26566e1e29413e883207d57cfe7bed4"
  dependencies:
    fbjs "^0.8.9"
    loose-envify "^1.3.1"
    object-assign "^4.1.1"

create-react-class@^15.5.2:
  version "15.5.2"
  resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.5.2.tgz#6a8758348df660b88326a0e764d569f274aad681"
>>>>>>> master

What am I missing?

@tricoder42 in case you haven't seen it already, that feature has been included in the 1.0.0 release that happened yesterday. Update Yarn and running yarn install should fix the conflicts for you.
I just tried and worked like charm!

Ah, sorry! Great stuff, thank you!

Was this page helpful?
0 / 5 - 0 ratings