vuejs/vue · error · Error
invalid target version: ${targetVersion}
Error message
invalid target version: ${targetVersion} What it means
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.
Source
Thrown at scripts/release.js:63
choices: versionIncrements.map(i => `${i} (${inc(i)})`).concat(['custom'])
})
if (release === 'custom') {
targetVersion = (
await prompt({
type: 'input',
name: 'version',
message: 'Input custom version',
initial: currentVersion
})
).version
} else {
targetVersion = release.match(/\((.*)\)/)[1]
}
}
if (!semver.valid(targetVersion)) {
throw new Error(`invalid target version: ${targetVersion}`)
}
const { yes } = await prompt({
type: 'confirm',
name: 'yes',
message: `Releasing v${targetVersion}. Confirm?`
})
if (!yes) {
return
}
// run tests before release
step('\nRunning tests...')
if (!skipTests && !isDryRun) {
await run('pnpm', ['test'])
} else {
console.log(`(skipped)`)View on GitHub (pinned to 9e88707940)
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.
Example fix
// before node scripts/release.js 3.0 node scripts/release.js v3.0.0 // after node scripts/release.js 3.0.0 node scripts/release.js 3.0.0-beta.1
Defensive patterns
Strategy: validation
Validate before calling
const semver = require('semver')
function assertTargetVersion(v) {
if (typeof v !== 'string' || semver.valid(v) == null) {
throw new Error(`Refusing to release: '${v}' is not a valid semver. Usage: node scripts/release.js <major.minor.patch>[-<preid>.<n>]`)
}
return v
}
// call BEFORE invoking the release script, or patch it into main() at line 62:
// assertTargetVersion(targetVersion)
// CLI wrapper example:
const target = process.argv[2]
assertTargetVersion(target)
// only then exec the script Type guard
const semver = require('semver')
const isSemverVersion = (v) =>
typeof v === 'string' && v.length > 0 && semver.valid(v) !== null
// usage
if (!isSemverVersion(targetVersion)) {
console.error(`Invalid version '${targetVersion}'. Expected e.g. 1.2.3 or 1.2.3-beta.1`)
process.exit(1)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [@vue/compiler-sfc] SFC contains no <script> tags.
- Invalid JSON bundle file: ${bundle}
- Cannot locate bundle file: ${bundle}
- Invalid server-rendering bundle format. Should be a string o
- renderer cache must implement at least get & set.
AI-assisted analysis of vuejs/vue@9e88707940 (2026-08-11).
Data as JSON: /api/errors/ed7aaaaa5eedc159.
Report an issue: GitHub.