{"record":{"id":"ed7aaaaa5eedc159","repo":"vuejs/vue","slug":"invalid-target-version-targetversion","errorCode":null,"errorMessage":"invalid target version: ${targetVersion}","messagePattern":"invalid target version: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/release.js","lineNumber":63,"sourceCode":"      choices: versionIncrements.map(i => `${i} (${inc(i)})`).concat(['custom'])\n    })\n\n    if (release === 'custom') {\n      targetVersion = (\n        await prompt({\n          type: 'input',\n          name: 'version',\n          message: 'Input custom version',\n          initial: currentVersion\n        })\n      ).version\n    } else {\n      targetVersion = release.match(/\\((.*)\\)/)[1]\n    }\n  }\n\n  if (!semver.valid(targetVersion)) {\n    throw new Error(`invalid target version: ${targetVersion}`)\n  }\n\n  const { yes } = await prompt({\n    type: 'confirm',\n    name: 'yes',\n    message: `Releasing v${targetVersion}. Confirm?`\n  })\n\n  if (!yes) {\n    return\n  }\n\n  // run tests before release\n  step('\\nRunning tests...')\n  if (!skipTests && !isDryRun) {\n    await run('pnpm', ['test'])\n  } else {\n    console.log(`(skipped)`)","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/vuejs/vue/blob/9e88707940088cb1f4cd7dd210c9168a50dc347c/scripts/release.js#L45-L81","documentation":"This error is thrown by the project's release script (scripts/release.js) when the resolved target version fails semver.valid(). It is a hard guard: no release proceeds unless targetVersion is a well-formed semantic version string. The script derives targetVersion from one of three sources — a CLI positional arg (args._[0]), a custom version typed into the enquirer prompt, or a substring extracted from a select choice of the form \"patch (1.2.3)\" via release.match(/\\((.*)\\)/)[1]. Any value that semver cannot parse (e.g. \"1.2\", \"v1.2.3-foo\", \"latest\") trips the guard.","triggerScenarios":"Running `node scripts/release.js 1.2` (no patch field), or `node scripts/release.js latest`. Selecting the \"custom\" prompt option and entering a non-semver string such as \"next\" or \"1.0\". Passing a flag like `--preid beta` but then supplying a non-prerelease-shaped version. Note: if a release string with no parentheses were matched, line 58 (`release.match(/\\((.*)\\)/)[1]`) would throw a TypeError before reaching this check, so this specific error only fires when a value IS obtained but is semver-invalid.","commonSituations":"Forgetting the patch digit (\"3.0\" instead of \"3.0.0\"). Including a leading \"v\" (\"v3.0.0\") that semver treats as invalid in some semver versions. Copy-pasting a version from a tag name that includes extra metadata. Mismatched preid: building a prerelease like \"3.0.0-beta\" while preId resolved to \"alpha\". CI invoking the script with a version variable that resolved empty or to a SHA.","solutions":["Pass a full semantic version as the only positional arg, e.g. `node scripts/release.js 3.0.0` (or `3.0.0-beta.1` if a preid is set).","If using the interactive prompt, pick one of the offered increment choices (which embed a valid semver in parentheses) rather than typing custom, OR type a complete semver into the custom field.","Strip any leading \"v\" and any non-semver suffix from the value before it reaches the script: `node scripts/release.js \"$(echo $V | sed 's/^v//')\"`.","When automating, validate first with `npx semver <version>` and exit non-zero before invoking the release script."],"exampleFix":"// before\nnode scripts/release.js 3.0\nnode scripts/release.js v3.0.0\n\n// after\nnode scripts/release.js 3.0.0\nnode scripts/release.js 3.0.0-beta.1","handlingStrategy":"validation","validationCode":"const semver = require('semver')\n\nfunction assertTargetVersion(v) {\n  if (typeof v !== 'string' || semver.valid(v) == null) {\n    throw new Error(`Refusing to release: '${v}' is not a valid semver. Usage: node scripts/release.js <major.minor.patch>[-<preid>.<n>]`)\n  }\n  return v\n}\n\n// call BEFORE invoking the release script, or patch it into main() at line 62:\n//   assertTargetVersion(targetVersion)\n// CLI wrapper example:\nconst target = process.argv[2]\nassertTargetVersion(target)\n// only then exec the script","typeGuard":"const semver = require('semver')\nconst isSemverVersion = (v) =>\n  typeof v === 'string' && v.length > 0 && semver.valid(v) !== null\n\n// usage\nif (!isSemverVersion(targetVersion)) {\n  console.error(`Invalid version '${targetVersion}'. Expected e.g. 1.2.3 or 1.2.3-beta.1`)\n  process.exit(1)\n}","tryCatchPattern":null,"preventionTips":["Always pass the full major.minor.patch triple; never shorthand to major.minor.","Keep preids consistent: if package.json is on an alpha prerelease, supply an alpha-tagged target.","In CI, validate the version variable with `npx semver` as a separate step before the release job so failures surface with a clear message.","Strip leading 'v' from git-tag-derived versions before passing them in."],"tags":["release-script","semver","cli","validation"],"analyzedSha":"9e88707940088cb1f4cd7dd210c9168a50dc347c","analyzedAt":"2026-08-11T22:22:01.295Z","schemaVersion":2},"datasetVersion":"2026-08-12T04:17:13.124Z"}