{"record":{"id":"ce5a016d5e4f5a06","repo":"yarnpkg/yarn","slug":"noname-ce5a01","errorCode":null,"errorMessage":"noName","messagePattern":"noName","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/pack.js","lineNumber":185,"sourceCode":"\nexport function setFlags(commander: Object) {\n  commander.description('Creates a compressed gzip archive of package dependencies.');\n  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","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/pack.js#L167-L203","documentation":"`yarn pack` builds a tarball of the current package and derives the filename from `pkg.name` (pack.js:190). It reads the root manifest and requires a `name`; a package.json with no `name` throws noName at pack.js:185 before any packing logic runs.","triggerScenarios":"Running `yarn pack` in a directory whose package.json omits the `name` field (e.g., a config-only or scaffold project).","commonSituations":"Generating a tarball for local testing before `name` was set; workspace root manifest without a name; accidental deletion of the field.","solutions":["Add a valid `name` to package.json.","Confirm you are running `yarn pack` from the package directory that owns the manifest you intend to pack.","Run `node -p \"require('./package.json').name\"` to verify the field resolves."],"exampleFix":"// before — package.json\n{\n  \"version\": \"1.0.0\"\n}\n// after\n{\n  \"name\": \"mylib\",\n  \"version\": \"1.0.0\"\n}","handlingStrategy":"validation","validationCode":"const pkg = require('./package.json');\nif (!pkg.name) {\n  throw new Error('Cannot pack: package.json has no \"name\".');\n}","typeGuard":"function isNamed(pkg) {\n  return typeof pkg === 'object' && pkg !== null && typeof pkg.name === 'string' && pkg.name.length > 0;\n}","tryCatchPattern":"try {\n  await runYarn(['pack']);\n} catch (e) {\n  if (/noName/.test(e.message)) {\n    console.error('Add a \"name\" to package.json before packing.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Set `name` at project init.","Run a manifest sanity check (`name` present) before any pack/publish step.","Keep pack/publish out of branches where package.json is mid-edit."],"tags":["cli","pack","manifest","package-json"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}