payloadcms/payload · error · APIError
The collection with slug ${String(collectionSlug)} can't be
Error message
The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation. What it means
Thrown by the Local API `duplicate` wrapper in packages/payload/src/collections/operations/local/duplicate.ts:115 when `payload.duplicate({ collection, id })` targets a slug not registered in `payload.collections`. Defaults to HTTP 500. It is the first of two guards in duplicateLocal — the second (error 145) checks `disableDuplicate`.
Source
Thrown at packages/payload/src/collections/operations/local/duplicate.ts:115
): Promise<TransformCollectionWithSelect<TSlug, TSelect>> {
const {
id,
collection: collectionSlug,
data,
depth,
disableTransaction,
draft,
overrideAccess = true,
populate,
select,
selectedLocales,
showHiddenFields,
} = options
const collection = payload.collections[collectionSlug]
if (!collection) {
throw new APIError(
`The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.`,
)
}
if (collection.config.disableDuplicate === true) {
throw new APIError(
`The collection with slug ${String(collectionSlug)} cannot be duplicated.`,
400,
)
}
const req = await createLocalReq(options as CreateLocalReqOptions, payload)
return duplicateOperation<TSlug, TSelect>({
id,
collection,
data,
depth,View on GitHub (pinned to 00c58b35c0)
Solutions
- Confirm the slug matches the collection config exactly.
- Validate dynamic slugs against `Object.keys(payload.collections)` before duplicating.
- Ensure `payload.init()` finished and the collection is registered.
- Remove `as CollectionSlug` casts so the compiler catches bad slugs.
Example fix
// before
await payload.duplicate({ collection: 'product' as CollectionSlug, id }) // slug is 'products'
// after
await payload.duplicate({ collection: 'products', id }) Defensive patterns
Strategy: validation
Validate before calling
function assertCollectionSlug(payload: Payload, slug: string): void {
if (!(slug in payload.collections)) {
throw new Error(`Unknown collection slug '${slug}'`)
}
}
assertCollectionSlug(payload, 'products')
await payload.duplicate({ collection: 'products', id }) Type guard
const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>
slug in (payload.collections as Record<string, unknown>)
if (slugIsRegistered(payload, slug)) {
await payload.duplicate({ collection: slug, id })
} Try / catch
try {
await payload.duplicate({ collection: slug, id })
} catch (err) {
if (err instanceof APIError && /Duplicate Operation/.test(err.message)) {
// unknown slug — correct it
} else throw err
} Prevention
- Validate slugs from admin/UI actions against payload.collections.
- Keep slug constants centralized.
- Avoid `as CollectionSlug` casts on runtime strings.
When it happens
Trigger: Calling `payload.duplicate({ collection: 'media-item', id })` when the real slug is `'media'`; duplicating from a generic action handler that receives an unvalidated slug; calling duplicate before `payload.init()` registers collections.
Common situations: Slug typo or stale constant; collection removed; plugin conditionally registering the collection not loaded; `as CollectionSlug` cast on a dynamic value.
Related errors
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/b7692e867a334b70.
Report an issue: GitHub.