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

时光总嘲笑我的痴心妄想 提交于 2019-12-08 14:31:50

问题


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.


回答1:


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)




回答2:


If all you are doing is a simple yarn install without any other flags or options passed in as well, you can optionally just use the yarn command and save typing a few characters.

Taken straight from Yarn's docs:

There are many options for installing dependencies, including:

  1. Installing all dependencies: yarn or yarn install

Both commands will do the same thing.



来源:https://stackoverflow.com/questions/41126217/how-to-sync-yarn-lock-with-package-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!