乐闻世界logo
搜索文章和话题

How to know the version of currently installed package from yarn.lock

1个答案

1

In Yarn, the yarn.lock file is a critical component that ensures version consistency for dependencies used in the project. When installing dependencies via Yarn, Yarn locks the specific versions of each dependency in the yarn.lock file to guarantee consistent installation of the same dependency versions, even if new versions of the dependencies have been released.

Steps to View Package Versions:

  1. Open the yarn.lock file: Locate and open the yarn.lock file in the project root directory. This file contains detailed information about all project dependencies, including version numbers and sources.

  2. Search for the specific package: In the yarn.lock file, find relevant entries by searching for the package name you want to check. For example, to verify the version of react, search for react in the file.

  3. View version information: After locating the package entry in the yarn.lock file, you will see information similar to the following:

    shell
    react@^16.8.0: version "16.8.6" resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#..." integrity sha512-...

    The version field specifies the exact version of react currently installed in the project, which is 16.8.6.

Example:

Suppose your project uses the lodash library, and you aim to verify its installed version. Follow these steps:

  1. Open the project's yarn.lock file.
  2. Use the search functionality of a text editor to input lodash.
  3. In the search results, find an entry similar to the following:
    shell
    lodash@^4.17.15: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#..." integrity sha512-...
    This indicates that the current version of lodash installed in your project is 4.17.20.

By following these steps, you can clearly identify the specific versions of packages used in the project, which is invaluable for dependency management, troubleshooting, and version upgrade decisions.

2024年7月20日 00:00 回复

你的答案