DEV Community

Boots
Boots

Posted on

22 4

Let Yarn Resolve Your Conflicts

Filing under: "How did I not know this?!?"


I am, generally speaking, conflict-averse.

But engineering, like life, guarantees the occasional conflict. And sometimes, this conflict occurs in the jungle that is your package manager's lock file.

To resolve a merge conflict in yarn.lock, I usually just delete it and run yarn again. This is the developer's equivalent of yelling "Tiny smoke bomb!" and running away.

Is this best practice? Probs not. Does it work? Pretty much always.

Well, today, I accidentally ran yarn before deleting my conflict-ridden yarn.lock.

To my delight, I got this message:

This is a thing! And I want the world to know it!!!

Yarn will try to resolve the merge conflicts in your lock file!

This feature was introduced with Yarn 1.0, it seems. Basically two years ago.

Sometimes it feels like I'm a little behind the times 😬

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (5)

Collapse
 
nickytonline profile image
Nick Taylor • • Edited

There's so much to know these days. Better late than never! 😉 For those using npm, it can do this as well. Simply run npm install --package-lock-only

Collapse
 
alexparra profile image
Alex Parra •

I’ve ran into a few of these in the past...
My solution has been to use the frozen-lock-file flag cause in those situations I wasn’t adding a dependency just installing missing ones.
Will check this next time around.
Thanks for sharing!

Collapse
 
lizzieshipwreck profile image
Lizzie Shipton •

You just changed my life. I feel like I wanna cry.

Collapse
 
brettimus profile image
Boots •

let it all out! yarn is here for us 🧶😭

Collapse
 
lizzieshipwreck profile image
Lizzie Shipton •

Also just wanted to update: ran it today and discovered that if the conflicts cannot be merged successfully, Yarn will simply regenerate a new one from scratch. So perhaps the old method isn't so wrong after all

Retry later