yarnpkg/yarn · error · MessageError

unknownPackageName

Error message

unknownPackageName

What it means

Thrown by getName() when no package name can be resolved at all: no positional argument was supplied AND config.readRootManifest().name is absent or empty. The 'tag' command cannot target any package without a name, so it aborts.

Source

Thrown at src/cli/commands/tag.js:27

import {normalizePattern} from '../../util/normalize-pattern.js';
import {isValidPackageName} from '../../util/normalize-manifest/validate.js';

export async function getName(args: Array<string>, config: Config): Promise<string> {
  let name = args.shift();

  if (!name) {
    const pkg = await config.readRootManifest();
    name = pkg.name;
  }

  if (name) {
    if (!isValidPackageName(name)) {
      throw new MessageError(config.reporter.lang('invalidPackageName'));
    }

    return NpmRegistry.escapeName(name);
  } else {
    throw new MessageError(config.reporter.lang('unknownPackageName'));
  }
}

async function list(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
  const name = await getName(args, config);

  reporter.step(1, 1, reporter.lang('gettingTags'));
  const tags = await config.registries.npm.request(`-/package/${name}/dist-tags`);

  if (tags) {
    reporter.info(`Package ${name}`);
    for (const name in tags) {
      reporter.info(`${name}: ${tags[name]}`);
    }
  }

  if (!tags) {
    throw new MessageError(reporter.lang('packageNotFoundRegistry', name, 'npm'));

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Add a 'name' field to the root package.json.
  2. Pass the package name as the first positional argument: 'yarn tag <name>'.
  3. Verify cwd contains the intended package.json with a name.

Example fix

// before (package.json)
{ "version": "1.0.0" }
// after
{ "name": "my-pkg", "version": "1.0.0" }
Defensive patterns

Strategy: validation

Validate before calling

const manifest = await config.readRootManifest();
if (!manifest || !manifest.name) {
  throw new Error('Cannot run tag: root package.json has no "name" field');
}

Type guard

function hasName(m: { name?: string }): m is { name: string } {
  return typeof m.name === 'string' && m.name.length > 0;
}

Prevention

When it happens

Trigger: Invoking 'yarn tag' (or 'yarn tag list' implicitly) with zero args in a project whose root package.json has no 'name' field, leaving the `name` variable falsy through both resolution paths.

Common situations: New/uninitialized project without a name; private workspace where the root manifest omits 'name'; running the command from the wrong cwd (a subfolder with no package.json).

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/a2902056b9a7c3bc. Report an issue: GitHub.