{"record":{"id":"41745ea5527124b8","repo":"yarnpkg/yarn","slug":"there-are-more-than-one-workspace-with-name-0","errorCode":null,"errorMessage":"There are more than one workspace with name $0","messagePattern":"There are more than one workspace with name \\$0","errorType":"validation","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/config.js","lineNumber":846,"sourceCode":"    for (const file of new Set([].concat(...files))) {\n      const loc = path.join(root, path.dirname(file));\n      const manifest = await this.findManifest(loc, false);\n\n      if (!manifest) {\n        continue;\n      }\n\n      if (!manifest.name) {\n        this.reporter.warn(this.reporter.lang('workspaceNameMandatory', loc));\n        continue;\n      }\n      if (!manifest.version) {\n        this.reporter.warn(this.reporter.lang('workspaceVersionMandatory', loc));\n        continue;\n      }\n\n      if (Object.prototype.hasOwnProperty.call(workspaces, manifest.name)) {\n        throw new MessageError(this.reporter.lang('workspaceNameDuplicate', manifest.name));\n      }\n\n      workspaces[manifest.name] = {loc, manifest};\n    }\n\n    return workspaces;\n  }\n\n  // workspaces functions\n  getWorkspaces(manifest: ?Manifest, shouldThrow: boolean = false): ?WorkspacesConfig {\n    if (!manifest || !this.workspacesEnabled) {\n      return undefined;\n    }\n\n    const ws = extractWorkspaces(manifest);\n\n    if (!ws) {\n      return ws;","sourceCodeStart":828,"sourceCodeEnd":864,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/config.js#L828-L864","documentation":"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.","triggerScenarios":"Two or more sub-packages matched by the `workspaces` globs declare the same `name` field in their respective package.json files.","commonSituations":"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.","solutions":["Find all workspace manifests with the duplicate name and give each a unique `name`.","Search: `grep -r '\"name\": \"<dup-name>\" packages/`.","Remove stale/copied package directories that are accidentally matched by the workspace glob.","Tighten the `workspaces` glob to exclude the offending folder."],"exampleFix":"// before: packages/app/package.json and packages/app-clone/package.json\n// both have:\n{ \"name\": \"my-app\" }\n// after: packages/app-clone/package.json\n{ \"name\": \"my-app-clone\" }","handlingStrategy":"validation","validationCode":"const glob = require('glob');\nconst fs = require('fs');\nconst path = require('path');\n\nfunction checkUniqueWorkspaceNames(rootGlobs) {\n  const names = {};\n  for (const g of rootGlobs) {\n    for (const dir of glob.sync(path.join(process.cwd(), g))) {\n      const pkgPath = path.join(dir, 'package.json');\n      if (!fs.existsSync(pkgPath)) continue;\n      const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));\n      if (names[pkg.name]) {\n        throw new Error(`Duplicate workspace name '${pkg.name}' in ${dir} and ${names[pkg.name]}`);\n      }\n      names[pkg.name] = dir;\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await config.resolveWorkspaces(root, rootManifest);\n} catch (err) {\n  if (err.message.includes('more than one workspace')) {\n    reporter.error('Two workspace packages share a name — rename one.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Enforce unique package `name` fields across all workspace packages via a precommit lint rule.","When copying a workspace package as a template, rename it immediately.","Tighten workspace globs so stale directories are not accidentally included."],"tags":["workspaces","manifest","naming","validation"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}