Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 783
Mauricio Pasquier Juan Avatar asked Dec 13 '16 16:12

Mauricio Pasquier Juan


People also ask

How do I sync yarn lock with package json?

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.

Does yarn read package lock json?

Every time a module is added, npm and Yarn create (or update) a package-lock. json and yarn. lock file respectively. This way, you can guarantee another machine installs the exact same package, while still having a range of allowed versions defined in package.

Should I commit package lock json and yarn lock?

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.

Why is yarn lock not updating?

Out-of-Sync Package.lock files are out of sync. For this, you could simply run yarn install and that should resolve the issue.


1 Answers

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)

like image 91
sdgluck Avatar answered Sep 27 '22 22:09

sdgluck