How to sync `yarn.lock` with `package.json`?

node.jspackage.jsonYarnpkg

node.js Problem Overview


I installed a package with yarn add --dev, run its setup process and during it, the package installed several other packages and added those to package.json (in devDependencies), I assume with npm. Great, but now my yarn.lock is out of sync.

What is the correct, non-manual way of syncing yarn.lock to the current state of package.json?

Edit: yarn check shows the missing packages as:

error Lockfile does not contain pattern: <package>@<version>

But it doesn't add them.

node.js Solutions


Solution 1 - node.js

Run yarn install, or just yarn.

The lock file is updated in its entirety on any change to dependencies, i.e. when you run a yarn command.

From the Yarn docs:

> Your yarn.lock file is auto-generated and should be handled entirely by Yarn. As you add/upgrade/remove dependencies with the Yarn CLI, it will automatically update your yarn.lock file. Do not edit this file directly as it is easy to break something.

(Emphasis my own)

Solution 2 - node.js

If you ever face a checksum issue this will solve it,

YARN_CHECKSUM_BEHAVIOR=update yarn

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMauricio Pasquier JuanView Question on Stackoverflow
Solution 1 - node.jssdgluckView Answer on Stackoverflow
Solution 2 - node.jsHarsh SainiView Answer on Stackoverflow