yarnpkg/yarn · error · MessageError

noName

Error message

noName

What it means

After the `private` check, publish.js:149-150 requires a `name`; a package.json without `name` throws noName because the registry PUT needs a package identifier and the tarball URI is derived from the name.

Source

Thrown at src/cli/commands/publish.js:150

  if (!await fs.exists(dir)) {
    throw new MessageError(reporter.lang('unknownFolderOrTarball'));
  }

  const stat = await fs.lstat(dir);
  let publishPath = dir;
  if (stat.isDirectory()) {
    config.cwd = path.resolve(dir);
    publishPath = config.cwd;
  }

  // validate package fields that are required for publishing
  // $FlowFixMe
  const pkg = await config.readRootManifest();
  if (pkg.private) {
    throw new MessageError(reporter.lang('publishPrivate'));
  }
  if (!pkg.name) {
    throw new MessageError(reporter.lang('noName'));
  }

  let registry: string = '';

  if (pkg && pkg.publishConfig && pkg.publishConfig.registry) {
    registry = pkg.publishConfig.registry;
  }

  reporter.step(1, 4, reporter.lang('bumpingVersion'));
  const commitVersion = await setVersion(config, reporter, flags, [], false);

  //
  reporter.step(2, 4, reporter.lang('loggingIn'));
  const revoke = await getToken(config, reporter, pkg.name, flags, registry);

  //
  reporter.step(3, 4, reporter.lang('publishing'));
  await publish(config, pkg, flags, publishPath);

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Add a valid, registry-unique `name` to package.json.
  2. Confirm ownership/availability of the name on the target registry before publishing.
  3. Re-run `yarn publish` only after the `name` field is present and non-empty.

Example fix

// before — package.json
{
  "version": "1.0.0"
}
// after
{
  "name": "mylib",
  "version": "1.0.0"
}
Defensive patterns

Strategy: validation

Validate before calling

const pkg = require('./package.json');
if (!pkg.name) {
  throw new Error('Cannot publish: package.json has no "name".');
}

Type guard

function hasPublishableName(pkg) {
  return typeof pkg === 'object' && pkg !== null && typeof pkg.name === 'string' && pkg.name.length > 0;
}

Try / catch

try {
  await runYarn(['publish']);
} catch (e) {
  if (/noName/.test(e.message)) {
    console.error('Add a registry-unique "name" to package.json before publishing.');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `yarn publish` on a manifest that has `version` (and possibly `private:false`) but no `name` field.

Common situations: Scaffold/template package.json with name omitted; field accidentally deleted; monorepo child manifest not yet given an identity.

Related errors


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