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 Version By ID Operation.

What it means

Thrown by the Local API `findVersionByID` wrapper in packages/payload/src/collections/operations/local/findVersionByID.ts:108 when `payload.findVersionByID({ collection, id })` targets a slug not in `payload.collections`. Defaults to HTTP 500. Only relevant for versioned collections.

Source

Thrown at packages/payload/src/collections/operations/local/findVersionByID.ts:108

  payload: Payload,
  options: Options<TSlug>,
): Promise<TypeWithVersion<DataFromCollectionSlug<TSlug>>> {
  const {
    id,
    collection: collectionSlug,
    depth,
    disableErrors = false,
    overrideAccess = true,
    populate,
    select,
    showHiddenFields,
    trash = false,
  } = options

  const collection = payload.collections[collectionSlug]

  if (!collection) {
    throw new APIError(
      `The collection with slug ${String(
        collectionSlug,
      )} can't be found. Find Version By ID Operation.`,
    )
  }

  return findVersionByIDOperation({
    id,
    collection,
    depth,
    disableErrors,
    overrideAccess,
    populate,
    req: await createLocalReq(options as CreateLocalReqOptions, payload),
    select,
    showHiddenFields,
    trash,
  })

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Confirm the slug matches the collection config exactly.
  2. Verify the collection still has versions enabled.
  3. Check `Object.keys(payload.collections)` at runtime.
  4. Remove `as CollectionSlug` casts on dynamic strings.

Example fix

// before
await payload.findVersionByID({ collection: 'page', id: versionId }) // slug is 'pages'

// after
await payload.findVersionByID({ collection: 'pages', id: versionId })
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, 'pages')
await payload.findVersionByID({ collection: 'pages', id: versionId })

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.findVersionByID({ collection: slug, id: versionId })
}

Try / catch

try {
  await payload.findVersionByID({ collection: slug, id: versionId })
} catch (err) {
  if (err instanceof APIError && /Find Version By ID Operation/.test(err.message)) {
    // unknown slug — correct it
  } else throw err
}

Prevention

When it happens

Trigger: Calling `payload.findVersionByID({ collection: 'page', id: versionId })` with a typo (real slug `'pages'`); querying a version after the collection's `versions` config was disabled or the collection removed; calling before `payload.init()`.

Common situations: Slug typo; collection rename; versions disabled so the slug path is stale; `as CollectionSlug` cast.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/51172e4a0d6b8341. Report an issue: GitHub.