{"record":{"id":"9195c019929cb66e","repo":"yarnpkg/yarn","slug":"invalidversion","errorCode":null,"errorMessage":"invalidVersion","messagePattern":"invalidVersion","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/version.js","lineNumber":89,"sourceCode":"    return flags.commitHooks === false || config.getOption('version-commit-hooks') === false;\n  }\n\n  if (pkg.scripts) {\n    // inherit `scripts` from manifest\n    Object.assign(scripts, pkg.scripts);\n  }\n\n  // get old version\n  let oldVersion = pkg.version;\n  if (oldVersion) {\n    reporter.info(`${reporter.lang('currentVersion')}: ${oldVersion}`);\n  } else {\n    oldVersion = '0.0.0';\n  }\n\n  // get new version\n  if (newVersion && !isValidNewVersion(oldVersion, newVersion, config.looseSemver, identifier)) {\n    throw new MessageError(reporter.lang('invalidVersion'));\n  }\n\n  // get new version by bumping old version, if requested\n  if (!newVersion) {\n    if (flags.major) {\n      newVersion = semver.inc(oldVersion, 'major');\n    } else if (flags.minor) {\n      newVersion = semver.inc(oldVersion, 'minor');\n    } else if (flags.patch) {\n      newVersion = semver.inc(oldVersion, 'patch');\n    } else if (flags.premajor) {\n      newVersion = semver.inc(oldVersion, 'premajor', identifier);\n    } else if (flags.preminor) {\n      newVersion = semver.inc(oldVersion, 'preminor', identifier);\n    } else if (flags.prepatch) {\n      newVersion = semver.inc(oldVersion, 'prepatch', identifier);\n    } else if (flags.prerelease) {\n      newVersion = semver.inc(oldVersion, 'prerelease', identifier);","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/version.js#L71-L107","documentation":"Thrown by 'yarn version' when --new-version is provided but isValidNewVersion(oldVersion, newVersion, config.looseSemver, identifier) returns false. The proposed version is not a valid semver relative to the existing version (and optional preid).","triggerScenarios":"Running 'yarn version --new-version <bad>' where <bad> is e.g. 'foo', '1.x', '1.2', or otherwise fails semver validation given the current version and identifier.","commonSituations":"Typo in the version string; user passed a range instead of a concrete version; pre-release identifier mismatch with --preid; loose-semver disabled and the value is too permissive.","solutions":["Provide a concrete, valid semver: 'yarn version --new-version 1.2.3'.","If you want to bump rather than set an exact version, use --patch/--minor/--major instead.","When using --preid, ensure --new-version is a valid prerelease form (e.g. '1.2.3-beta.1') consistent with the identifier."],"exampleFix":"# before\n$ yarn version --new-version 1.x\n# after\n$ yarn version --new-version 1.2.3","handlingStrategy":"validation","validationCode":"import semver from 'semver';\n\nfunction assertValidNewVersion(oldVersion: string, newVersion: string, loose: boolean, identifier?: string) {\n  if (!isValidNewVersion(oldVersion, newVersion, loose, identifier)) {\n    throw new Error(`Invalid version \"${newVersion}\" relative to current \"${oldVersion}\"`);\n  }\n}\n// or simply: if (!semver.valid(newVersion)) throw ...","typeGuard":"import semver from 'semver';\nfunction isValidVersionInput(v: unknown): v is string {\n  return typeof v === 'string' && semver.valid(v) !== null;\n}","tryCatchPattern":null,"preventionTips":["Validate candidate versions with semver.valid before passing them to 'yarn version'.","Prefer bump flags to avoid hand-typed version strings.","Keep --preid and --new-version consistent in release scripts."],"tags":["semver","validation","cli-args"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}