{"record":{"id":"10d3e51cdc133a34","repo":"withastro/astro","slug":"duplicatecontententryslugerror","errorCode":"DuplicateContentEntrySlugError","errorMessage":"**${collection}** contains multiple entries with the same slug: `${id}`. Slugs must be unique.\n\nEntries: \n- ${fileName}\n- ${fileName}","messagePattern":"\\*\\*(.+?)\\*\\* contains multiple entries with the same slug: `(.+?)`\\. Slugs must be unique\\.\n\nEntries: \n- (.+?)\n- (.+?)","errorType":"error_code","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/loaders/file.ts","lineNumber":94,"sourceCode":"\t\t\t}\n\t\t\tlogger.debug(`Found ${data.length} item array in ${fileName}`);\n\t\t\tstore.clear();\n\t\t\tconst idList = new Set();\n\t\t\tfor (const rawItem of data) {\n\t\t\t\tconst id = (rawItem.id ?? rawItem.slug)?.toString();\n\t\t\t\tif (!id) {\n\t\t\t\t\tlogger.error(`Item in ${fileName} is missing an id or slug field.`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (idList.has(id)) {\n\t\t\t\t\tconst message = DuplicateContentEntrySlugError.message(\n\t\t\t\t\t\tcollection,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tfileName,\n\t\t\t\t\t\tfileName,\n\t\t\t\t\t);\n\t\t\t\t\tif (config.prerenderConflictBehavior === 'error') {\n\t\t\t\t\t\tthrow new AstroError({\n\t\t\t\t\t\t\t...DuplicateContentEntrySlugError,\n\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (config.prerenderConflictBehavior !== 'ignore') {\n\t\t\t\t\t\tlogger.warn(message);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tidList.add(id);\n\t\t\t\tconst parsedData = await parseData({ id, data: rawItem, filePath });\n\t\t\t\tstore.set({ id, data: parsedData, filePath: normalizedFilePath });\n\t\t\t}\n\t\t} else if (typeof data === 'object') {\n\t\t\tconst entries = Object.entries<Record<string, unknown>>(data);\n\t\t\tlogger.debug(`Found object with ${entries.length} entries in ${fileName}`);\n\t\t\tstore.clear();\n\t\t\tfor (const [id, rawItem] of entries) {\n\t\t\t\tif (id === '$schema' && typeof rawItem === 'string') {\n\t\t\t\t\t// Ignore JSON schema field.","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/content/loaders/file.ts#L76-L112","documentation":"In the array form, the file() loader derives each entry's id from its `id` or `slug` field and requires uniqueness. When two items resolve to the same id within one file, Astro reports DuplicateContentEntrySlugError — a warning by default, a thrown error when `prerenderConflictBehavior` is set to 'error'. The message lists the same file twice because both colliding entries live in that one file.","triggerScenarios":"Two objects in the loaded array with the same `id` (or `slug`) value; ids that differ in the source but stringify identically (e.g. numeric 1 and string '1' both become '1' via toString()).","commonSituations":"Copy-pasted entries in a hand-maintained JSON/YAML data file; YAML numeric ids colliding with string ids after coercion; large datasets where duplicate slugs slip in unnoticed during editing.","solutions":["Find the duplicated id/slug printed in the message and make it unique in the data file.","If ids come from user content, normalize them (slugify) and append a suffix on collision before writing the file.","Only if duplicates are acceptable, adjust `prerenderConflictBehavior` ('warn' logs, 'ignore' silences) — but the store will keep the last entry for a duplicate id."],"exampleFix":"// before (data.json)\n[\n  { \"id\": \"getting-started\", \"title\": \"Getting Started\" },\n  { \"id\": \"getting-started\", \"title\": \"Getting Started (old)\" }\n]\n\n// after\n[\n  { \"id\": \"getting-started\", \"title\": \"Getting Started\" },\n  { \"id\": \"getting-started-v1\", \"title\": \"Getting Started (old)\" }\n]","handlingStrategy":"validation","validationCode":"function hasUniqueIds(items: Array<Record<string, any>>): boolean {\n  const ids = items.map((i) => (i.id ?? i.slug)?.toString()).filter(Boolean);\n  return new Set(ids).size === ids.length;\n}\n\nif (!hasUniqueIds(data)) {\n  const seen = new Set<string>();\n  const dup = data.find((i) => {\n    const id = (i.id ?? i.slug)?.toString();\n    if (seen.has(id)) return true;\n    seen.add(id);\n    return false;\n  });\n  throw new Error(`Duplicate id: ${dup?.id ?? dup?.slug}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await getCollection('authors');\n} catch (err) {\n  if ((err as any)?.code === 'DuplicateContentEntrySlugError') {\n    // the message names the colliding slug; dedupe it in the data file and re-sync\n  } else throw err;\n}","preventionTips":["Validate id uniqueness in a CI check over JSON/YAML data files.","Watch for silent collisions after toString() coercion (numeric 1 vs string '1').","Decide deliberately on `prerenderConflictBehavior` — the default only warns, so duplicates can hide."],"tags":["content-collections","file-loader","duplicate-id","data-quality"],"backgroundTag":"duplicate-entry-id","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}