{"record":{"id":"7408351688355e89","repo":"yarnpkg/yarn","slug":"noversion-740835","errorCode":null,"errorMessage":"noVersion","messagePattern":"noVersion","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/pack.js","lineNumber":188,"sourceCode":"  commander.option('-f, --filename <filename>', 'filename');\n}\n\nexport function hasWrapper(commander: Object, args: Array<string>): boolean {\n  return true;\n}\n\nexport async function run(\n  config: Config,\n  reporter: Reporter,\n  flags: {filename?: string},\n  args?: Array<string>,\n): Promise<void> {\n  const pkg = await config.readRootManifest();\n  if (!pkg.name) {\n    throw new MessageError(reporter.lang('noName'));\n  }\n  if (!pkg.version) {\n    throw new MessageError(reporter.lang('noVersion'));\n  }\n\n  const normaliseScope = name => (name[0] === '@' ? name.substr(1).replace('/', '-') : name);\n  const filename = flags.filename || path.join(config.cwd, `${normaliseScope(pkg.name)}-v${pkg.version}.tgz`);\n\n  await config.executeLifecycleScript('prepack');\n\n  const stream = await pack(config);\n\n  await new Promise((resolve, reject) => {\n    stream.pipe(fs2.createWriteStream(filename));\n    stream.on('error', reject);\n    stream.on('close', resolve);\n  });\n\n  await config.executeLifecycleScript('postpack');\n\n  reporter.success(reporter.lang('packWroteTarball', filename));","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/pack.js#L170-L206","documentation":"Right after the `name` check, `yarn pack` requires a `version` (pack.js:188) because the tarball filename embeds the version (`${name}-v${version}.tgz`, pack.js:190). A package.json with `name` but no `version` throws noVersion.","triggerScenarios":"Running `yarn pack` when package.json has a `name` but no `version` field (or version is empty).","commonSituations":"Project initialized with `yarn init` and version skipped/blanked; version managed by another tool that hasn't written it yet at pack time.","solutions":["Add a semver `version` to package.json (e.g., \"1.0.0\").","Run `yarn version --new-version <x.y.z>` to set it before packing.","Ensure any version-bumping step (e.g., standard-version, release tool) runs before `yarn pack`."],"exampleFix":"// before — package.json\n{\n  \"name\": \"mylib\"\n}\n// after\n{\n  \"name\": \"mylib\",\n  \"version\": \"1.0.0\"\n}","handlingStrategy":"validation","validationCode":"const pkg = require('./package.json');\nif (!pkg.version) {\n  throw new Error('Cannot pack: package.json has no \"version\".');\n}","typeGuard":"function hasVersion(pkg) {\n  return typeof pkg === 'object' && pkg !== null && typeof pkg.version === 'string' && pkg.version.length > 0;\n}","tryCatchPattern":"try {\n  await runYarn(['pack']);\n} catch (e) {\n  if (/noVersion/.test(e.message)) {\n    console.error('Set a \"version\" in package.json before packing.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Run any version-bumping tool (standard-version, etc.) before `yarn pack`.","Assert `version` is present in a pre-pack script.","Treat name+version as required pair for any distributable package."],"tags":["cli","pack","manifest","version"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}