{"record":{"id":"a39613cad18fc44d","repo":"yarnpkg/yarn","slug":"can-t-install-from-a-lockfile-of-version-version","errorCode":null,"errorMessage":"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.","messagePattern":"Can't install from a lockfile of version (.+?) as you're on an old yarn version that only supports versions up to (.+?)\\. Run `\\$ yarn self-update` to upgrade to the latest version\\.","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/lockfile/parse.js","lineNumber":189,"sourceCode":"    this.fileLoc = fileLoc;\n  }\n\n  fileLoc: string;\n  token: Token;\n  tokens: Iterator<Token>;\n  comments: Array<string>;\n\n  onComment(token: Token) {\n    const value = token.value;\n    invariant(typeof value === 'string', 'expected token value to be a string');\n\n    const comment = value.trim();\n\n    const versionMatch = comment.match(VERSION_REGEX);\n    if (versionMatch) {\n      const version = +versionMatch[1];\n      if (version > LOCKFILE_VERSION) {\n        throw new MessageError(\n          `Can't install from a lockfile of version ${version} as you're on an old yarn version that only supports ` +\n            `versions up to ${LOCKFILE_VERSION}. Run \\`$ yarn self-update\\` to upgrade to the latest version.`,\n        );\n      }\n    }\n\n    this.comments.push(comment);\n  }\n\n  next(): Token {\n    const item = this.tokens.next();\n    invariant(item, 'expected a token');\n\n    const {done, value} = item;\n    if (done || !value) {\n      throw new Error('No more tokens');\n    } else if (value.type === TOKEN_TYPES.comment) {\n      this.onComment(value);","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/lockfile/parse.js#L171-L207","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Upgrade Yarn classic to the latest version: `yarn self-update` (or use `corepack` / nvm to pin a newer Yarn).","Align all environments (local + CI) to the same Yarn version.","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`.","Pin Yarn version via `yarn policies set-version <version>` or a `package.json` `packageManager` field."],"exampleFix":"# before\n# yarn lockfile v2   <-- generated by newer Yarn\n# fix: upgrade Yarn\nyarn self-update\n# or regenerate with current Yarn:\nrm yarn.lock\nyarn install","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst {LOCKFILE_VERSION} = require('./src/constants.js');\nfunction checkLockfileVersion(filePath) {\n  const head = fs.readFileSync(filePath, 'utf8').split('\\n')[0];\n  const m = head.match(/yarn lockfile v(\\d+)/);\n  if (m && Number(m[1]) > LOCKFILE_VERSION) {\n    throw new Error(`Lockfile v${m[1]} is newer than supported v${LOCKFILE_VERSION}. Upgrade Yarn or regenerate.`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await parseLockfile(fileLoc);\n} catch (err) {\n  if (err instanceof MessageError && err.message.includes(\"Can't install from a lockfile\")) {\n    reporter.error('Upgrade Yarn (`yarn self-update`) or regenerate yarn.lock.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Pin a single Yarn version across all environments (engines.yarn, corepack, or .yvm).","Do not commit a Yarn Berry (v2+) yarn.lock into a Yarn classic project.","Document the Yarn version in the project README or `packageManager` field."],"tags":["lockfile","version","compatibility","upgrade"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}