apify/crawlee · error · Error
Unsupported format: '${format}'. Use one of ${supportedForma
Error message
Unsupported format: '${format}'. Use one of ${supportedFormats.join(', ')} What it means
When an explicit format is provided (or inferred from the path extension), BasicCrawler validates it against the list of supported formats (json, csv). If the format is not supported, this error is thrown naming the valid choices.
Source
Thrown at packages/basic-crawler/src/internals/basic-crawler.ts:2270
* Retrieves all the data from the default crawler {@apilink Dataset} and exports them to the specified format.
* Supported formats are currently 'json' and 'csv', and will be inferred from the `path` automatically.
*/
async exportData<Data>(path: string, format?: 'json' | 'csv', options?: DatasetExportOptions): Promise<Data[]> {
const supportedFormats = ['json', 'csv'];
const formatMatch = /\.(json|csv)$/i.exec(path);
if (!format && formatMatch) {
format = formatMatch[1].toLowerCase() as 'json' | 'csv';
}
if (!format) {
throw new Error(
`Failed to infer format from the path: '${path}'. Supported formats: ${supportedFormats.join(', ')}`,
);
}
if (!supportedFormats.includes(format)) {
throw new Error(`Unsupported format: '${format}'. Use one of ${supportedFormats.join(', ')}`);
}
const dataset = await this.getDataset();
const items = await dataset.export(options);
if (format === 'csv') {
let value: string;
if (items.length === 0) {
value = '';
} else {
const keys = options?.collectAllKeys
? Array.from(new Set(items.flatMap(Object.keys)))
: Object.keys(items[0]);
const { stringify } = await import('csv-stringify/sync');
value = stringify([
keys,View on GitHub (pinned to dbe57fb09c)
Solutions
- Use 'json' or 'csv' as the format value
- If you need another format, export as JSON and convert afterwards with your own code
- Check the casing of the format string (it must match the supported list, e.g. lowercase 'csv')
Example fix
// before
await crawler.exportTo('data.xml', { format: 'xml' });
// after
await crawler.exportTo('data.json', { format: 'json' }); Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED = ['json','csv'];
if (format && !SUPPORTED.includes(format.toLowerCase())) throw new Error(`Unsupported format ${format}; use json or csv`); Try / catch
try { await crawler.exportTo(p, { format }); } catch (e) { if (String(e.message).startsWith('Unsupported format')) { /* retry with 'json' */ } else throw e; } Prevention
- Hardcode only 'json' or 'csv' as format values
- Centralize export options in a constant to avoid typos/casing mistakes
When it happens
Trigger: Passing a format option such as 'xml', 'xlsx', 'ndjson', or 'JSONL' to the dataset export call, or an explicit format that doesn't match 'json' or 'csv'.
Common situations: Users assuming Excel/NDJSON export is supported; passing uppercase 'JSON' while supportedFormats comparison is case-sensitive; copying options from other data libraries.
Related errors
- Failed to infer format from the path: '${path}'. Supported f
- Invalid "proxyUrl". Unsupported protocol: ${proxyUrl}.
- `alwaysEnqueue` cannot be used together with a custom `uniqu
- At least one of "sources" or "sourcesFunction" must be provi
- "${domain}" is not a valid hostname. The `domains` option ta
AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30).
Data as JSON: /api/errors/f2b675a8231b4540.
Report an issue: GitHub.