{"record":{"id":"9eba6ab64e5fdb70","repo":"withastro/astro","slug":"collection-contains-multiple-entries-with-t","errorCode":null,"errorMessage":"**${collection}** contains multiple entries with the same slug: `${slug}`. Slugs must be unique.\n\nEntries: \n- ${preExisting}\n- ${alsoFound}","messagePattern":"\\*\\*(.+?)\\*\\* contains multiple entries with the same slug: `(.+?)`\\. Slugs must be unique\\.\n\nEntries: \n- (.+?)\n- (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/astro/src/content/loaders/file.ts","lineNumber":99,"sourceCode":"\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.\n\t\t\t\t\tcontinue;\n\t\t\t\t}\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}","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/content/loaders/file.ts#L81-L117","documentation":"Two items in a file()-loaded data array resolved to the same id (from the item's `id` or `slug` field). The DuplicateContentEntrySlugError message names the collection and the colliding id; depending on the astro.config option prerenderConflictBehavior (default 'warn') this either throws an AstroError, logs this warning, or is silenced. Either way the later entry overwrites the earlier one in the store.","triggerScenarios":"Two objects in the array sharing the same id (or slug) value; ids are coerced with toString(), so numeric 1 and string \"1\" also collide.","commonSituations":"Copy-pasted entries in JSON/YAML data; ids derived from titles that collide after normalization; merging data files from multiple sources without deduplication.","solutions":["Make every entry's id (or slug) unique in the data file","Set prerenderConflictBehavior: 'error' in astro.config.mjs during development so collisions fail the build early instead of silently overwriting","If collisions come from upstream data, preprocess the file to dedupe before Astro reads it"],"exampleFix":"// before: src/data/tags.json\n[\n  { \"id\": \"news\", \"label\": \"News\" },\n  { \"id\": \"news\", \"label\": \"News (old)\" }\n]\n\n// after\n[\n  { \"id\": \"news\", \"label\": \"News\" },\n  { \"id\": \"news-archive\", \"label\": \"News (old)\" }\n]","handlingStrategy":"validation","validationCode":"// Detect duplicate ids/slug collisions before Astro loads the file\nimport { readFileSync } from 'node:fs';\nfunction findDuplicateIds(path: string): string[] {\n  const items: Array<Record<string, unknown>> = JSON.parse(readFileSync(path, 'utf-8'));\n  const ids = items.map((i) => String(i.id ?? i.slug));\n  return [...new Set(ids.filter((id, i) => ids.indexOf(id) !== i))];\n}","typeGuard":null,"tryCatchPattern":"// With prerenderConflictBehavior: 'error', duplicate ids throw during content sync:\nimport { AstroError } from 'astro';\ntry {\n  await runContentSync(); // astro sync / build, e.g. via the Astro JS API\n} catch (err) {\n  if (err instanceof AstroError && err.name === 'DuplicateContentEntrySlugError') {\n    console.error('Fix duplicate ids listed in:', err.message);\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Make id/slug the unique key of your data model and review it in code review","Set prerenderConflictBehavior: 'error' in CI so collisions fail builds instead of overwriting entries","Deduplicate merged data files programmatically before they reach the loader"],"tags":["astro","content-collections","file-loader","duplicate-id","slug-conflict"],"backgroundTag":"duplicate-content-slug","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"}