yarnpkg/yarn · error · MessageError

Can't install from a lockfile of version ${version} as you'r

Error message

Can't install from a lockfile of version ${version} as you're on an old yarn version that only supports versions up to ${LOCKFILE_VERSION}. Run `$ yarn self-update` to upgrade to the latest version.

What it means

Thrown by the lockfile parser's `onComment` handler when the `# yarn lockfile vN` comment at the top of yarn.lock reports a version `N` greater than the `LOCKFILE_VERSION` constant (currently 1) supported by this Yarn binary. Yarn refuses to install from a lockfile format newer than it understands.

Source

Thrown at src/lockfile/parse.js:189

    this.fileLoc = fileLoc;
  }

  fileLoc: string;
  token: Token;
  tokens: Iterator<Token>;
  comments: Array<string>;

  onComment(token: Token) {
    const value = token.value;
    invariant(typeof value === 'string', 'expected token value to be a string');

    const comment = value.trim();

    const versionMatch = comment.match(VERSION_REGEX);
    if (versionMatch) {
      const version = +versionMatch[1];
      if (version > LOCKFILE_VERSION) {
        throw new MessageError(
          `Can't install from a lockfile of version ${version} as you're on an old yarn version that only supports ` +
            `versions up to ${LOCKFILE_VERSION}. Run \`$ yarn self-update\` to upgrade to the latest version.`,
        );
      }
    }

    this.comments.push(comment);
  }

  next(): Token {
    const item = this.tokens.next();
    invariant(item, 'expected a token');

    const {done, value} = item;
    if (done || !value) {
      throw new Error('No more tokens');
    } else if (value.type === TOKEN_TYPES.comment) {
      this.onComment(value);

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Upgrade Yarn classic to the latest version: `yarn self-update` (or use `corepack` / nvm to pin a newer Yarn).
  2. Align all environments (local + CI) to the same Yarn version.
  3. If the lockfile came from Yarn Berry, either migrate the whole project to Berry or regenerate the lockfile with classic: `rm yarn.lock && yarn install`.
  4. Pin Yarn version via `yarn policies set-version <version>` or a `package.json` `packageManager` field.

Example fix

# before
# yarn lockfile v2   <-- generated by newer Yarn
# fix: upgrade Yarn
yarn self-update
# or regenerate with current Yarn:
rm yarn.lock
yarn install
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const {LOCKFILE_VERSION} = require('./src/constants.js');
function checkLockfileVersion(filePath) {
  const head = fs.readFileSync(filePath, 'utf8').split('\n')[0];
  const m = head.match(/yarn lockfile v(\d+)/);
  if (m && Number(m[1]) > LOCKFILE_VERSION) {
    throw new Error(`Lockfile v${m[1]} is newer than supported v${LOCKFILE_VERSION}. Upgrade Yarn or regenerate.`);
  }
}

Try / catch

try {
  await parseLockfile(fileLoc);
} catch (err) {
  if (err instanceof MessageError && err.message.includes("Can't install from a lockfile")) {
    reporter.error('Upgrade Yarn (`yarn self-update`) or regenerate yarn.lock.');
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: A yarn.lock generated by a newer Yarn (or Yarn Berry emitting v2+ lockfile) is consumed by an older Yarn classic binary whose `LOCKFILE_VERSION` is lower than the file's declared version.

Common situations: Downgrading Yarn after a teammate upgraded. A CI runner has an older global Yarn than developers' machines. Accidentally committing a Yarn Berry (v2+) yarn.lock into a Yarn classic project.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/a39613cad18fc44d. Report an issue: GitHub.