apify/crawlee · error · Error

Failed to infer format from the path: '${path}'. Supported f

Error message

Failed to infer format from the path: '${path}'. Supported formats: ${supportedFormats.join(', ')}

What it means

BasicCrawler's dataset export helper infers the export format (json or csv) from the file extension of the destination path. If no explicit format option is given and the path has no .json or .csv extension, the format cannot be determined, so the crawler throws this error listing the supported formats.

Source

Thrown at packages/basic-crawler/src/internals/basic-crawler.ts:2264

    async getData(...args: Parameters<Dataset['getData']>): ReturnType<Dataset['getData']> {
        const dataset = await this.getDataset();
        return dataset.getData(...args);
    }

    /**
     * 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)))

View on GitHub (pinned to dbe57fb09c)

Solutions

  1. Add a .json or .csv extension to the export path, e.g. 'data/output.json'
  2. Pass an explicit format option ('json' or 'csv') alongside the path
  3. Check the path for typos or environment variable interpolation that may have dropped the extension

Example fix

// before
await crawler.exportTo('results/data');
// after
await crawler.exportTo('results/data.json');
Defensive patterns

Strategy: validation

Validate before calling

if (!/\.(json|csv)$/i.test(path)) throw new Error(`Export path must end in .json or .csv: ${path}`);

Try / catch

try { await crawler.exportTo(path); } catch (e) { if (String(e.message).includes('Failed to infer format')) { /* fall back to path + '.json' */ } else throw e; }

Prevention

When it happens

Trigger: Calling the crawler's dataset export (e.g. via an export path option) with a path lacking a .json or .csv extension (e.g. 'output.txt', 'result', or an extensionless path) without passing an explicit format option.

Common situations: Users writing datasets to files with unusual extensions like .ndjson, .jsonl, .txt, or a timestamped filename with no extension; passing a directory path instead of a file path.

Related errors


AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30). Data as JSON: /api/errors/d11db124c32a9716. Report an issue: GitHub.