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:
-
Open the
yarn.lockfile: Locate and open theyarn.lockfile in the project root directory. This file contains detailed information about all project dependencies, including version numbers and sources. -
Search for the specific package: In the
yarn.lockfile, find relevant entries by searching for the package name you want to check. For example, to verify the version ofreact, search forreactin the file. -
View version information: After locating the package entry in the
yarn.lockfile, you will see information similar to the following:shellreact@^16.8.0: version "16.8.6" resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#..." integrity sha512-...The
versionfield specifies the exact version ofreactcurrently installed in the project, which is16.8.6.
Example:
Suppose your project uses the lodash library, and you aim to verify its installed version. Follow these steps:
- Open the project's
yarn.lockfile. - Use the search functionality of a text editor to input
lodash. - In the search results, find an entry similar to the following:
This indicates that the current version ofshelllodash@^4.17.15: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#..." integrity sha512-...lodashinstalled in your project is4.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.