Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the `version` in yarn.lock `__metadata`?

Tags:

yarnpkg

At the top of my yarn.lock file I see:

__metadata:
  version: 5
  cacheKey: 8

I have no idea what the version or cacheKey is, and I haven't found any documentation for them on yarn's website. What are they?

like image 645
Stud Sterkel Avatar asked Oct 16 '25 20:10

Stud Sterkel


1 Answers

It's simply the yarn.lock version, originally introduced here:

When upgraded, the lockfile entries have to be resolved again (but the specific versions are still pinned, no worry). Bump it when you change the fields within the Package type; no more no less.

More details on the currently implemented resolution logic:

github.com/yarnpkg/berry/blob/master/packages/yarnpkg-core/sources/Project.ts


Typical scenario

My lockfile version updated locally because my latest Homebrew Yarn version was running behind on 3.2.0-rc.10, despite running brew upgrade and yarn -v still showing this older version.

However a bot (might be team member) already upgraded Yarn to 3.2.0-rc.12, versioned / committed / locked remotely in .yarnrc.yml and npm.packageManager (example).

This is what we want for consistency, so we could add a package.json script to use it instead

// ...
  "scripts": {
    // ...
    "setup": "yarn",
    // ...
// ...

If frequently switching between classic, stable and canary - cd ~ && yarn set version <ver> may bump your local Yarn version too (then remember to clear generated files).

like image 191
Leo Avatar answered Oct 19 '25 11:10

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!