{"record":{"id":"311fa05dcbf242f2","repo":"yarnpkg/yarn","slug":"requiredversioninrange","errorCode":null,"errorMessage":"requiredVersionInRange","messagePattern":"requiredVersionInRange","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/tag.js","lineNumber":95,"sourceCode":"    return true;\n  }\n}\n\nexport function setFlags(commander: Object) {\n  commander.description('Add, remove, or list tags on a package.');\n}\n\nexport const {run, hasWrapper, examples} = buildSubCommands(\n  'tag',\n  {\n    async add(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<boolean> {\n      if (args.length !== 2) {\n        return false;\n      }\n\n      const {name, range, hasVersion} = normalizePattern(args.shift());\n      if (!hasVersion) {\n        throw new MessageError(reporter.lang('requiredVersionInRange'));\n      }\n      if (!isValidPackageName(name)) {\n        throw new MessageError(reporter.lang('invalidPackageName'));\n      }\n\n      const tag = args.shift();\n\n      reporter.step(1, 3, reporter.lang('loggingIn'));\n      const revoke = await getToken(config, reporter, name);\n\n      reporter.step(2, 3, reporter.lang('creatingTag', tag, range));\n      const result = await config.registries.npm.request(\n        `-/package/${NpmRegistry.escapeName(name)}/dist-tags/${encodeURI(tag)}`,\n        {\n          method: 'PUT',\n          body: range,\n        },\n      );","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/tag.js#L77-L113","documentation":"Thrown in the 'tag add' subcommand when normalizePattern(args.shift()) yields hasVersion === false. The first argument to 'tag add' must be a 'name@version' pattern; without a version component, there is nothing to point the tag at.","triggerScenarios":"Running 'yarn tag add <name> <tag>' where <name> has no '@<version>' suffix, so normalizePattern reports no version segment.","commonSituations":"User assumes 'tag add' takes name and version as separate args; forgot the '@'; pattern uses ':' or '=' instead of '@'.","solutions":["Provide the version inline: 'yarn tag add <name>@<version> <tag>'.","Verify the version exists on the registry before tagging it.","Use a concrete version (e.g. 1.2.3) or a resolvable range that resolves to a single published version."],"exampleFix":"# before\n$ yarn tag add my-pkg latest\n# after\n$ yarn tag add my-pkg@1.2.3 latest","handlingStrategy":"validation","validationCode":"const {name, range, hasVersion} = normalizePattern(input);\nif (!hasVersion) {\n  throw new Error(`Pattern \"${input}\" must include a version, e.g. \"${input}@1.2.3\"`);\n}","typeGuard":"function patternHasVersion(input: string): boolean {\n  // name@version: the last '@' must not be at index 0 (scope) and must be followed by a non-empty range\n  const at = input.lastIndexOf('@');\n  return at > 0 && at < input.length - 1;\n}","tryCatchPattern":null,"preventionTips":["Always pass 'name@version' to 'yarn tag add'.","Resolve the version programmatically (e.g. from semver.highest on the registry) before constructing the arg.","Document the expected CLI form in project scripts."],"tags":["validation","cli-args","semver"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}