payloadcms/payload · error · APIError
Collection with slug ${collectionSlug} not found
Error message
Collection with slug ${collectionSlug} not found What it means
createImport resolves the target collection from req.payload.config.collections by slug. If no registered collection matches collectionSlug, it throws a 400. (Note: the inner `if (!collectionSlug)` is dead code since line 94 already guards the empty-slug case.)
Source
Thrown at packages/plugin-import-export/src/import/createImport.ts:119
if (debug) {
req.payload.logger.debug({
fileName: file.name,
fileSize: file.data.length,
mimeType: file.mimetype,
msg: 'File info',
})
}
const collectionConfig = req.payload.config.collections.find(
({ slug }) => slug === collectionSlug,
)
if (!collectionConfig) {
if (!collectionSlug) {
throw new APIError('Collection slug is required', 400, null, true)
}
throw new APIError(`Collection with slug ${collectionSlug} not found`, 400, null, true)
}
// Get disabled fields configuration
const disabledFields =
collectionConfig.admin?.custom?.['plugin-import-export']?.disabledFields ?? []
const importHooks = collectionConfig.custom?.['plugin-import-export']?.importHooks
// Get beforeImport functions for field transformations
const importFieldHooks = getImportFieldFunctions({
fields: collectionConfig.flattenedFields || [],
})
// Parse the file data
let originalDocs: Record<string, unknown>[] | undefined
let documents: Record<string, unknown>[]
if (format === 'csv') {
const rawData = await parseCSV({View on GitHub (pinned to 00c58b35c0)
Solutions
- Verify collectionSlug exactly matches a slug in payload.config.collections.
- Log req.payload.config.collections.map(c => c.slug) at the call site to confirm membership.
- If the collection lives in a plugin, ensure the plugin is added to the config before this runs.
Defensive patterns
Strategy: validation
Validate before calling
const slugs = new Set(req.payload.config.collections.map((c) => c.slug))
if (!slugs.has(collectionSlug)) {
throw new Error(`Unknown collection slug: ${collectionSlug}`)
}
await createImport({ collectionSlug, ... }) Type guard
const isRegisteredSlug = (slug: string, req: PayloadRequest): boolean => req.payload.config.collections.some((c) => c.slug === slug)
Prevention
- Centralize slug references as named constants instead of string literals.
- Add a startup self-check that all import target slugs exist in config.
- After renaming a collection, grep for the old slug across import callers.
When it happens
Trigger: collectionSlug is misspelled, refers to a collection not added to the Payload config, or belongs to a different Payload instance. Also when a collection was renamed but the import caller still uses the old slug.
Common situations: Renaming a collection without updating import config; importing into a collection declared by a plugin that was never installed; copy-paste of a slug from another project.
Related errors
- Collection config not found for: ${importCollection}
- No file data provided for import
- Import file contains ${documents.length} documents but limit
- Import document not found: ${importId}
- Unable to determine mimetype for file: ${importDoc.filename}
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/a3458198eb7fdd75.
Report an issue: GitHub.