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. Find Operation. What it means
Thrown by the Local API `find` wrapper in packages/payload/src/collections/operations/local/find.ts:229 when `payload.find({ collection })` references a slug not present in `payload.collections`. Defaults to HTTP 500 (no status passed). Raised before pagination, where-clause parsing, or access control.
Source
Thrown at packages/payload/src/collections/operations/local/find.ts:229
draft = false,
includeLockStatus,
joins,
limit,
overrideAccess = true,
page,
pagination = true,
populate,
select,
showHiddenFields,
sort,
trash = false,
where,
} = options
const collection = payload.collections[collectionSlug]
if (!collection) {
throw new APIError(
`The collection with slug ${String(collectionSlug)} can't be found. Find Operation.`,
)
}
return findOperation<TSlug, TSelect>({
collection,
currentDepth,
depth,
disableErrors,
draft,
includeLockStatus,
joins,
limit,
overrideAccess,
page,
pagination,
populate,
req: await createLocalReq(options as CreateLocalReqOptions, payload),View on GitHub (pinned to 00c58b35c0)
Solutions
- Match the slug to the collection config's `slug` value exactly.
- Log `Object.keys(payload.collections)` to confirm registration at runtime.
- Make sure `payload.init()` resolved before the find call.
- Avoid `as CollectionSlug` casts on runtime strings.
Example fix
// before
const { docs } = await payload.find({ collection: 'post' }) // slug is 'posts'
// after
const { docs } = await payload.find({ collection: 'posts' }) 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, 'posts')
await payload.find({ collection: 'posts' }) 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.find({ collection: slug })
} Try / catch
try {
await payload.find({ collection: slug })
} catch (err) {
if (err instanceof APIError && /Find Operation/.test(err.message)) {
// unknown slug — log registered slugs and correct
} else throw err
} Prevention
- Share slug constants between config and callers.
- Await payload.init() in scripts before find calls.
- Avoid `as CollectionSlug` casts on dynamic input.
When it happens
Trigger: Calling `payload.find({ collection: 'post' })` with a typo (real slug `'posts'`); a frontend/server component fetching data with a hardcoded slug after the collection was renamed; calling find in a beforeInit hook before collections are registered.
Common situations: Stale slug constant after a rename; singular/plural confusion; `as CollectionSlug` cast on dynamic input; collection registered by a plugin that isn't loaded in this build.
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/d84a2a214de95be4.
Report an issue: GitHub.