{"record":{"id":"457cc4fedb34c464","repo":"payloadcms/payload","slug":"collection-slug-already-in-use-config-collecti","errorCode":null,"errorMessage":"Collection slug already in use: \"${config.collections![i]!.slug}\"","messagePattern":"Collection slug already in use: \"(.+?)\"","errorType":"http","errorClass":"DuplicateCollection","httpStatus":500,"severity":"critical","filePath":"packages/payload/src/config/sanitize.ts","lineNumber":405,"sourceCode":"        existingFieldNames: new Set(),\n        fields: sanitizedBlock.fields,\n        parentIsLocalized: false,\n        richTextSanitizers,\n        validRelationships,\n      })\n\n      const flattenedSanitizedBlock = flattenBlock({ block })\n\n      config.blocks.push(flattenedSanitizedBlock)\n    }\n  }\n\n  // Track orderable join fields during sanitization\n  const orderableJoins: OrderableJoinInfo[] = []\n\n  for (let i = 0; i < config.collections!.length; i++) {\n    if (collectionSlugs.has(config.collections![i]!.slug)) {\n      throw new DuplicateCollection('slug', config.collections![i]!.slug)\n    }\n\n    collectionSlugs.add(config.collections![i]!.slug)\n\n    const draftsConfig = config.collections![i]?.versions?.drafts\n\n    if (typeof draftsConfig === 'object' && draftsConfig.schedulePublish) {\n      schedulePublishCollections.push(config.collections![i]!.slug)\n    }\n\n    if (config.collections![i]!.enableQueryPresets) {\n      queryPresetsCollections.push(config.collections![i]!.slug)\n\n      if (!validRelationships.includes(queryPresetsCollectionSlug)) {\n        validRelationships.push(queryPresetsCollectionSlug)\n      }\n    }\n","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/config/sanitize.ts#L387-L423","documentation":"Thrown at sanitize time when two collections declare the same `slug`. Collection slugs are the primary key for the REST API, the DB table name, and cross-collection references, so duplicates are fatal. The check maintains a `Set` of slugs and raises `DuplicateCollection` on the second occurrence.","triggerScenarios":"Two collection configs with `{ slug: 'posts' }`; a plugin that registers a collection colliding with one you defined; copy-pasting a collection config and forgetting to rename the slug.","commonSituations":"Adding a plugin that brings its own `users`/`media` collection while you also define one; refactoring slugs and leaving a stale duplicate; monorepo shared config imported twice.","solutions":["Rename one of the colliding collections' `slug` to a unique value.","If a plugin registers the conflicting collection, disable or override it rather than redefining.","Grep the config tree for the duplicated slug to find both definitions."],"exampleFix":"// before\ncollections: [\n  { slug: 'media', upload: true, fields: [] },\n  { slug: 'media', upload: true, fields: [] },\n]\n// after\ncollections: [\n  { slug: 'media', upload: true, fields: [] },\n  { slug: 'documents', upload: true, fields: [] },\n]","handlingStrategy":"validation","validationCode":"const slugs = config.collections.map((c) => c.slug)\nconst dup = slugs.find((s, i) => slugs.indexOf(s) !== i)\nif (dup) {\n  throw new Error(`Duplicate collection slug: '${dup}'`)\n}","typeGuard":"function collectionSlugsUnique(collections: { slug: string }[]): boolean {\n  const seen = new Set<string>()\n  for (const c of collections) {\n    if (seen.has(c.slug)) return false\n    seen.add(c.slug)\n  }\n  return true\n}","tryCatchPattern":null,"preventionTips":["Assert unique slugs in a config unit test before buildConfig.","Watch for plugins that register collections colliding with yours.","Use a consistent naming convention to avoid accidental reuse."],"tags":["config","collections","sanitize","duplicate","buildconfig"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}