{"record":{"id":"0f94db5c36b0ab9c","repo":"payloadcms/payload","slug":"a-field-with-the-name-fieldname-was-found-mul","errorCode":null,"errorMessage":"A field with the name '${fieldName}' was found multiple times on the same level. Field names must be unique.","messagePattern":"A field with the name '(.+?)' was found multiple times on the same level\\. Field names must be unique\\.","errorType":"exception","errorClass":"DuplicateFieldName","httpStatus":500,"severity":"error","filePath":"packages/payload/src/fields/config/sanitize.ts","lineNumber":350,"sourceCode":"    ]\n  }\n\n  // Array ID field\n  if (field.type === 'array' && field.fields) {\n    const hasCustomID = field.fields.some((f) => 'name' in f && f.name === 'id')\n    if (!hasCustomID) {\n      field.fields.push(baseIDField)\n    }\n  }\n\n  // Blocks/array labels\n  if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n    field.labels = field.labels || formatLabels(field.name)\n  }\n\n  if (fieldAffectsData) {\n    if (existingFieldNames.has(field.name)) {\n      throw new DuplicateFieldName(field.name)\n    } else if (!['blockName', 'id'].includes(field.name)) {\n      existingFieldNames.add(field.name)\n    }\n\n    if (typeof field.localized !== 'undefined') {\n      if (!config.localization) {\n        delete field.localized\n      }\n    }\n\n    if (typeof field.validate === 'undefined') {\n      if ('virtual' in field && field.virtual) {\n        field.validate = (): true => true\n      } else {\n        const defaultValidate = validations[field.type as keyof typeof validations]\n        if (defaultValidate) {\n          field.validate = (val: any, options: any) =>\n            defaultValidate(val, { ...field, ...options })","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/fields/config/sanitize.ts#L332-L368","documentation":"Two data-affecting fields at the same nesting level share the same `name`. Payload tracks field names per level in an `existingFieldNames` set; a duplicate would map to the same DB column and admin form key, so it is rejected. (`blockName` and `id` are exempt because they are system-managed.)","triggerScenarios":"Two `{ name: 'title', type: 'text' }` in one collection's fields; a group containing two children with the same name; a tab and a sibling field sharing a name.","commonSituations":"Copy-pasting a field and forgetting to rename; merging two configs; refactoring tabs/groups and accidentally producing two same-named fields at the same level.","solutions":["Rename one of the duplicate fields to a unique name within that level.","If the duplication is intentional, separate the fields into different groups or named tabs (each named tab/group has its own name scope).","Search the offending level's fields for the reported name to find both occurrences."],"exampleFix":"// before\nfields: [\n  { name: 'title', type: 'text' },\n  { name: 'title', type: 'textarea' }\n]\n// after\nfields: [\n  { name: 'title', type: 'text' },\n  { name: 'subtitle', type: 'textarea' }\n]","handlingStrategy":"validation","validationCode":"function findDuplicateFieldNames(fields) {\n  const seen = new Set(); const dupes = []\n  for (const f of fields) {\n    if (!f?.name || ['blockName','id'].includes(f.name)) continue\n    if (seen.has(f.name)) dupes.push(f.name); else seen.add(f.name)\n  }\n  return dupes\n}\n// run per collection/global and per group/tab/array scope","typeGuard":"function fieldsAreUniqueByName(fields: any[]): boolean {\n  const names = fields.filter(f => f?.name && !['blockName','id'].includes(f.name)).map(f => f.name)\n  return new Set(names).size === names.length\n}","tryCatchPattern":"try {\n  await payload.init({ config })\n} catch (err) {\n  if (err?.name === 'DuplicateFieldName') console.error('Duplicate field name:', err?.message)\n  throw err\n}","preventionTips":["When merging field arrays from multiple modules, dedupe by name first.","Add a unit test that asserts each collection's top-level field names are unique."],"tags":["field-name","duplicate","config","schema","sanitization"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}