{"record":{"id":"038f2e5bc8cd4a97","repo":"nodejs/node","slug":"tag-name-must-not-be-a-valid-semver-range-defau","errorCode":null,"errorMessage":"Tag name must not be a valid SemVer range: ${defaultTag.trim()}","messagePattern":"Tag name must not be a valid SemVer range: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/publish.js","lineNumber":90,"sourceCode":"  }\n\n  get #command () {\n    return this.isStage ? 'stage' : 'publish'\n  }\n\n  async #publish (args, { workspace } = {}) {\n    log.verbose(this.#command, replaceInfo(args))\n\n    const unicode = this.npm.config.get('unicode')\n    const dryRun = this.npm.config.get('dry-run')\n    const json = this.npm.config.get('json')\n    const defaultTag = this.npm.config.get('tag')\n    const ignoreScripts = this.npm.config.get('ignore-scripts')\n    const scriptShell = this.npm.config.get('script-shell') || undefined\n    const { silent } = this.npm\n\n    if (semver.validRange(defaultTag)) {\n      throw new Error('Tag name must not be a valid SemVer range: ' + defaultTag.trim())\n    }\n\n    const opts = { ...this.npm.flatOptions, progress: false }\n\n    // you can publish name@version, ./foo.tgz, etc even though the default is the 'file:.' cwd.\n    const spec = npa(args[0])\n    let manifest = await this.#getManifest(spec, opts)\n\n    // only run scripts for directory type publishes\n    if (spec.type === 'directory' && !ignoreScripts) {\n      await runScript({\n        event: 'prepublishOnly',\n        path: spec.fetchSpec,\n        stdio: 'inherit',\n        pkg: manifest,\n        scriptShell,\n      })\n    }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/publish.js#L72-L108","documentation":"Thrown by the `npm publish` command when the configured default tag (from `npm config get tag`, typically 'latest') is itself a valid SemVer range. npm dist-tags use arbitrary string names (like 'latest', 'beta', 'next'), and if the tag name looks like a SemVer range (e.g. '1.0.0', '>=1.0.0', '1.x'), it would be ambiguous with version ranges in resolution and is explicitly rejected.","triggerScenarios":"The `defaultTag` variable is read from `this.npm.config.get('tag')`. If someone sets `tag=1.0.0` or `tag=>=1.0.0` in .npmrc or via `--tag`, `semver.validRange(defaultTag)` returns truthy and the error fires.","commonSituations":"Mistakenly setting `tag` to a version string in .npmrc instead of a named tag. Confusing the `--tag` flag (dist-tag name) with a version. Copy-publishing scripts that pass a version where a tag name belongs. CI scripts that dynamically set `--tag` to a version variable.","solutions":["Use a named tag that is not a SemVer range: 'latest', 'beta', 'next', 'alpha'","Check your .npmrc for a `tag=` line and ensure it is a word, not a version","If using --tag in a script, pass a dist-tag name, not a version number","Reset to default: `npm config delete tag`"],"exampleFix":"// before — in .npmrc or CLI\ntag=1.0.0\n// or: npm publish --tag 2.1.0\n\n// after — use a named dist-tag\ntag=latest\n// or: npm publish --tag beta","handlingStrategy":"validation","validationCode":"const semver = require('semver')\nfunction isValidDistTag(tag) {\n  return typeof tag === 'string' && tag.length > 0 && !semver.validRange(tag)\n}\n// Before publishing:\nconst tag = npm.config.get('tag')\nif (!isValidDistTag(tag)) {\n  throw new Error(`Tag \"${tag}\" is a valid SemVer range — use a named tag like 'latest', 'beta', 'next'`)\n}","typeGuard":"function isNonSemverTag(tag) {\n  const semver = require('semver')\n  return typeof tag === 'string' && tag.length > 0 && !semver.validRange(tag)\n}","tryCatchPattern":"try {\n  await exec([pkgSpec])\n} catch (e) {\n  if (e.message.includes('Tag name must not be a valid SemVer')) {\n    console.error('Set a named dist-tag: npm publish --tag latest')\n  }\n  throw e\n}","preventionTips":["Use named dist-tags like 'latest', 'beta', 'next', 'alpha' — never version numbers","Check .npmrc for tag= and ensure it is a word, not a SemVer string","In CI scripts, ensure the --tag flag receives a named tag, not a version variable","Reset to default if unsure: npm config delete tag"],"tags":["npm","publish","semver","dist-tag","config","cli"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}