apify/crawlee · error · Error
Unsupported content type: ${contentType}
Error message
Unsupported content type: ${contentType} What it means
Dataset.exportTo() only supports 'application/json' (and CSV via the CSV path); passing any other contentType reaches the terminal guard and throws. The content type determines how dataset items are serialized into the target key-value store.
Source
Thrown at packages/core/src/storages/dataset.ts:437
const { stringify } = await import('csv-stringify/sync');
const value = stringify([
keys,
...items.map((item) => {
return keys.map((k) => item[k]);
}),
]);
await kvStore.setValue(key, value, { contentType });
return items;
}
if (contentType === 'application/json') {
await kvStore.setValue(key, items);
return items;
}
throw new Error(`Unsupported content type: ${contentType}`);
}
/**
* Save entire default dataset's contents into one JSON file within a key-value store.
*
* @param key The name of the value to save the data in.
* @param [options] An optional options object where you can provide the target KVS name.
*/
async exportToJSON(key: string, options?: Omit<DatasetExportToOptions, 'fromDataset'>) {
await this.exportTo(key, options, 'application/json');
}
/**
* Save entire default dataset's contents into one CSV file within a key-value store.
*
* @param key The name of the value to save the data in.
* @param [options] An optional options object where you can provide the target KVS name.
*/View on GitHub (pinned to dbe57fb09c)
Solutions
- Use exactly 'application/json' for JSON export or 'text/csv' for CSV export.
- Export as JSON and convert to the desired format yourself afterwards.
- Validate/normalize any user-supplied content type against the supported set before calling exportTo.
- Check the current crawlee docs for newly supported formats; upgrade if a needed format exists in a newer version.
Example fix
// before
await dataset.exportTo('out', kvStore, 'text/json'); // unsupported
// after
await dataset.exportTo('out', kvStore, 'application/json'); Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED = ['application/json', 'text/csv'];
if (!SUPPORTED.includes(contentType)) {
throw new Error(`Use one of ${SUPPORTED.join(', ')}`);
}
await dataset.exportTo(key, kvStore, contentType); Type guard
type SupportedContentType = 'application/json' | 'text/csv';
function isSupportedContentType(x: string): x is SupportedContentType {
return x === 'application/json' || x === 'text/csv';
} Try / catch
try {
await dataset.exportTo(key, kvStore, contentType);
} catch (e) {
if (e instanceof Error && e.message.startsWith('Unsupported content type')) {
await dataset.exportTo(key, kvStore, 'application/json');
} else throw e;
} Prevention
- Only pass the exact constants 'application/json' or 'text/csv'.
- Type parameters as the supported union instead of plain string.
- Convert to other formats (XML, NDJSON) yourself after a JSON export.
When it happens
Trigger: Calling dataset.exportTo(key, kvStore, 'text/csv' as any) or any misspelled/unsupported type string that is not application/json (or text/csv on the CSV path).
Common situations: Typo in the content type constant, expecting XML/NDJSON support that does not exist, or passing a variable holding an arbitrary MIME type from user input.
Related errors
- Data item${s}is not an object. You can push only objects int
- Data item${s}is not serializable to JSON. Cause: ${err.messa
- dataset.getData(): The response is too large for parsing. Yo
- Dataset.forEach/map/reduce() support only a "json" format.
- The "value" parameter must be a String, Buffer, ArrayBuffer,
AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30).
Data as JSON: /api/errors/3c70d0104c05b55c.
Report an issue: GitHub.