{"record":{"id":"d11db124c32a9716","repo":"apify/crawlee","slug":"failed-to-infer-format-from-the-path-path-s","errorCode":null,"errorMessage":"Failed to infer format from the path: '${path}'. Supported formats: ${supportedFormats.join(', ')}","messagePattern":"Failed to infer format from the path: '(.+?)'\\. Supported formats: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/basic-crawler/src/internals/basic-crawler.ts","lineNumber":2264,"sourceCode":"    async getData(...args: Parameters<Dataset['getData']>): ReturnType<Dataset['getData']> {\n        const dataset = await this.getDataset();\n        return dataset.getData(...args);\n    }\n\n    /**\n     * Retrieves all the data from the default crawler {@apilink Dataset} and exports them to the specified format.\n     * Supported formats are currently 'json' and 'csv', and will be inferred from the `path` automatically.\n     */\n    async exportData<Data>(path: string, format?: 'json' | 'csv', options?: DatasetExportOptions): Promise<Data[]> {\n        const supportedFormats = ['json', 'csv'];\n\n        const formatMatch = /\\.(json|csv)$/i.exec(path);\n        if (!format && formatMatch) {\n            format = formatMatch[1].toLowerCase() as 'json' | 'csv';\n        }\n\n        if (!format) {\n            throw new Error(\n                `Failed to infer format from the path: '${path}'. Supported formats: ${supportedFormats.join(', ')}`,\n            );\n        }\n\n        if (!supportedFormats.includes(format)) {\n            throw new Error(`Unsupported format: '${format}'. Use one of ${supportedFormats.join(', ')}`);\n        }\n\n        const dataset = await this.getDataset();\n        const items = await dataset.export(options);\n\n        if (format === 'csv') {\n            let value: string;\n            if (items.length === 0) {\n                value = '';\n            } else {\n                const keys = options?.collectAllKeys\n                    ? Array.from(new Set(items.flatMap(Object.keys)))","sourceCodeStart":2246,"sourceCodeEnd":2282,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/basic-crawler/src/internals/basic-crawler.ts#L2246-L2282","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a .json or .csv extension to the export path, e.g. 'data/output.json'","Pass an explicit format option ('json' or 'csv') alongside the path","Check the path for typos or environment variable interpolation that may have dropped the extension"],"exampleFix":"// before\nawait crawler.exportTo('results/data');\n// after\nawait crawler.exportTo('results/data.json');","handlingStrategy":"validation","validationCode":"if (!/\\.(json|csv)$/i.test(path)) throw new Error(`Export path must end in .json or .csv: ${path}`);","typeGuard":null,"tryCatchPattern":"try { await crawler.exportTo(path); } catch (e) { if (String(e.message).includes('Failed to infer format')) { /* fall back to path + '.json' */ } else throw e; }","preventionTips":["Always end export paths with .json or .csv","Pass an explicit format option when the path extension is dynamic"],"tags":["configuration","dataset-export","validation"],"backgroundTag":"unsupported-export-format","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}