{"record":{"id":"679706bb7e515ec0","repo":"yarnpkg/yarn","slug":"unknownpackagename","errorCode":null,"errorMessage":"unknownPackageName","messagePattern":"unknownPackageName","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/link.js","lineNumber":56,"sourceCode":"\n      if (await fs.exists(src)) {\n        const folder = await getRegistryFolder(config, name);\n        const dest = path.join(folder, name);\n\n        await fs.unlink(dest);\n        await fs.mkdirp(path.dirname(dest));\n        await fs.symlink(src, dest);\n        reporter.success(reporter.lang('linkUsing', name));\n      } else {\n        throw new MessageError(reporter.lang('linkMissing', name));\n      }\n    }\n  } else {\n    // add cwd module to the global registry\n    const manifest = await config.readRootManifest();\n    const name = manifest.name;\n    if (!name) {\n      throw new MessageError(reporter.lang('unknownPackageName'));\n    }\n\n    const linkLoc = path.join(config.linkFolder, name);\n    if (await fs.exists(linkLoc)) {\n      reporter.warn(reporter.lang('linkCollision', name));\n    } else {\n      await fs.mkdirp(path.dirname(linkLoc));\n      await fs.symlink(config.cwd, linkLoc);\n\n      // If there is a `bin` defined in the package.json,\n      // link each bin to the global bin\n      if (manifest.bin) {\n        const globalBinFolder = await getGlobalBinFolder(config, flags);\n        for (const binName in manifest.bin) {\n          const binSrc = manifest.bin[binName];\n          const binSrcLoc = path.join(linkLoc, binSrc);\n          const binDestLoc = path.join(globalBinFolder, binName);\n          if (await fs.exists(binDestLoc)) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/link.js#L38-L74","documentation":"When `yarn link` is run with no arguments, yarn registers the current working-directory module into the global link folder (link.js:53-56). It reads the root manifest and requires a `name`; a package.json without a `name` field throws unknownPackageName because yarn has nothing to name the symlink under config.linkFolder.","triggerScenarios":"Running bare `yarn link` in a project whose package.json has no `name`, or whose package.json failed to load an identity (e.g., only a `package-lock.json`, or an incomplete scaffold).","commonSituations":"Fresh project initialized with `yarn init -y` but name left blank; monorepo sub-folder without its own package.json picking up a nameless root; typo deleting the `name` field.","solutions":["Add a valid `name` field to the package.json in the current directory.","Ensure you are running `yarn link` from the package root that contains the package.json you intend to register.","Validate the manifest with `node -e \"console.log(require('./package.json').name)\"` before linking."],"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('package.json is missing a \"name\" field; cannot `yarn link`.');\n}","typeGuard":"function hasName(pkg) {\n  return typeof pkg === 'object' && pkg !== null && typeof pkg.name === 'string' && pkg.name.length > 0;\n}","tryCatchPattern":"try {\n  await runYarn(['link']);\n} catch (e) {\n  if (/unknownPackageName/.test(e.message)) {\n    console.error('Add a \"name\" to package.json before registering for linking.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Always set `name` during `yarn init`.","In monorepos, give every linkable child package its own named package.json.","Validate manifests in a pre-commit hook."],"tags":["cli","link","manifest","package-json"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}