yarnpkg/yarn · error · MessageError

There are more than one workspace with name $0

Error message

There are more than one workspace with name $0

What it means

Thrown by `resolveWorkspaces` while iterating discovered workspace manifests: if a manifest's `name` already exists as a key in the `workspaces` map, Yarn throws because workspace names must be unique for dependency resolution and hoisting to be unambiguous.

Source

Thrown at src/config.js:846

    for (const file of new Set([].concat(...files))) {
      const loc = path.join(root, path.dirname(file));
      const manifest = await this.findManifest(loc, false);

      if (!manifest) {
        continue;
      }

      if (!manifest.name) {
        this.reporter.warn(this.reporter.lang('workspaceNameMandatory', loc));
        continue;
      }
      if (!manifest.version) {
        this.reporter.warn(this.reporter.lang('workspaceVersionMandatory', loc));
        continue;
      }

      if (Object.prototype.hasOwnProperty.call(workspaces, manifest.name)) {
        throw new MessageError(this.reporter.lang('workspaceNameDuplicate', manifest.name));
      }

      workspaces[manifest.name] = {loc, manifest};
    }

    return workspaces;
  }

  // workspaces functions
  getWorkspaces(manifest: ?Manifest, shouldThrow: boolean = false): ?WorkspacesConfig {
    if (!manifest || !this.workspacesEnabled) {
      return undefined;
    }

    const ws = extractWorkspaces(manifest);

    if (!ws) {
      return ws;

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Find all workspace manifests with the duplicate name and give each a unique `name`.
  2. Search: `grep -r '"name": "<dup-name>" packages/`.
  3. Remove stale/copied package directories that are accidentally matched by the workspace glob.
  4. Tighten the `workspaces` glob to exclude the offending folder.

Example fix

// before: packages/app/package.json and packages/app-clone/package.json
// both have:
{ "name": "my-app" }
// after: packages/app-clone/package.json
{ "name": "my-app-clone" }
Defensive patterns

Strategy: validation

Validate before calling

const glob = require('glob');
const fs = require('fs');
const path = require('path');

function checkUniqueWorkspaceNames(rootGlobs) {
  const names = {};
  for (const g of rootGlobs) {
    for (const dir of glob.sync(path.join(process.cwd(), g))) {
      const pkgPath = path.join(dir, 'package.json');
      if (!fs.existsSync(pkgPath)) continue;
      const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
      if (names[pkg.name]) {
        throw new Error(`Duplicate workspace name '${pkg.name}' in ${dir} and ${names[pkg.name]}`);
      }
      names[pkg.name] = dir;
    }
  }
}

Try / catch

try {
  await config.resolveWorkspaces(root, rootManifest);
} catch (err) {
  if (err.message.includes('more than one workspace')) {
    reporter.error('Two workspace packages share a name — rename one.');
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Two or more sub-packages matched by the `workspaces` globs declare the same `name` field in their respective package.json files.

Common situations: A monorepo with `packages/app/package.json` and `packages/server/package.json` both named `"app"`. Templated package.json copied without renaming. A package renamed in one location but a stale copy lingers in another glob-matched folder.

Related errors


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