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. Delete Operation. What it means
Thrown by the Local API `delete` wrapper in packages/payload/src/collections/operations/local/delete.ts:170 when `payload.delete({ collection })` references a slug not in `payload.collections`. Defaults to HTTP 500 (no status supplied). Thrown before transaction or access handling begins, so nothing is partially deleted.
Source
Thrown at packages/payload/src/collections/operations/local/delete.ts:170
): Promise<BulkOperationResult<TSlug, TSelect> | TransformCollectionWithSelect<TSlug, TSelect>> {
const {
id,
collection: collectionSlug,
depth,
disableTransaction,
overrideAccess = true,
overrideLock,
populate,
select,
showHiddenFields,
trash = false,
where,
} = options
const collection = payload.collections[collectionSlug]
if (!collection) {
throw new APIError(
`The collection with slug ${String(collectionSlug)} can't be found. Delete Operation.`,
)
}
const args = {
id,
collection,
depth,
disableTransaction,
overrideAccess,
overrideLock,
populate,
req: await createLocalReq(options as CreateLocalReqOptions, payload),
select,
showHiddenFields,
trash,
where,
}View on GitHub (pinned to 00c58b35c0)
Solutions
- Verify the slug against the collection config and `Object.keys(payload.collections)`.
- If deleting in a loop over many collections, filter the list to registered slugs first.
- Ensure `payload.init()` completed and the relevant collection plugin is loaded.
- Stop asserting dynamic strings as `CollectionSlug`.
Example fix
// before
await payload.delete({ collection: 'tag', where: { id: { equals: id } } }) // slug is 'tags'
// after
await payload.delete({ collection: 'tags', where: { id: { equals: 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, 'tags')
await payload.delete({ collection: 'tags', where: { id: { equals: 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.delete({ collection: slug, where: { id: { equals: id } } })
} Try / catch
try {
await payload.delete({ collection: slug, where })
} catch (err) {
if (err instanceof APIError && /Delete Operation/.test(err.message)) {
// unknown slug — fix caller, no retry
} else throw err
} Prevention
- When deleting across many collections, filter the list to registered slugs first.
- Keep slug constants in sync with the collection config.
- Avoid `as CollectionSlug` casts on dynamic slugs.
When it happens
Trigger: Calling `payload.delete({ collection: 'comment', where: {...} })` with a misspelled slug; deleting through a cleanup job that was written against a collection since removed; passing a slug sourced from a config file that is out of sync with the running Payload instance.
Common situations: Collection renamed or removed in a refactor; plural/singular mismatch; dynamic slug from env var; `as CollectionSlug` cast hiding a typo.
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/0e9673aa26383419.
Report an issue: GitHub.