{"record":{"id":"3c70d0104c05b55c","repo":"apify/crawlee","slug":"unsupported-content-type-contenttype","errorCode":null,"errorMessage":"Unsupported content type: ${contentType}","messagePattern":"Unsupported content type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storages/dataset.ts","lineNumber":437,"sourceCode":"\n            const { stringify } = await import('csv-stringify/sync');\n\n            const value = stringify([\n                keys,\n                ...items.map((item) => {\n                    return keys.map((k) => item[k]);\n                }),\n            ]);\n            await kvStore.setValue(key, value, { contentType });\n            return items;\n        }\n\n        if (contentType === 'application/json') {\n            await kvStore.setValue(key, items);\n            return items;\n        }\n\n        throw new Error(`Unsupported content type: ${contentType}`);\n    }\n\n    /**\n     * Save entire default dataset's contents into one JSON file within a key-value store.\n     *\n     * @param key The name of the value to save the data in.\n     * @param [options] An optional options object where you can provide the target KVS name.\n     */\n    async exportToJSON(key: string, options?: Omit<DatasetExportToOptions, 'fromDataset'>) {\n        await this.exportTo(key, options, 'application/json');\n    }\n\n    /**\n     * Save entire default dataset's contents into one CSV file within a key-value store.\n     *\n     * @param key The name of the value to save the data in.\n     * @param [options] An optional options object where you can provide the target KVS name.\n     */","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/storages/dataset.ts#L419-L455","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nawait dataset.exportTo('out', kvStore, 'text/json'); // unsupported\n\n// after\nawait dataset.exportTo('out', kvStore, 'application/json');","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['application/json', 'text/csv'];\nif (!SUPPORTED.includes(contentType)) {\n    throw new Error(`Use one of ${SUPPORTED.join(', ')}`);\n}\nawait dataset.exportTo(key, kvStore, contentType);","typeGuard":"type SupportedContentType = 'application/json' | 'text/csv';\nfunction isSupportedContentType(x: string): x is SupportedContentType {\n    return x === 'application/json' || x === 'text/csv';\n}","tryCatchPattern":"try {\n    await dataset.exportTo(key, kvStore, contentType);\n} catch (e) {\n    if (e instanceof Error && e.message.startsWith('Unsupported content type')) {\n        await dataset.exportTo(key, kvStore, 'application/json');\n    } else throw e;\n}","preventionTips":["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."],"tags":["dataset","export","content-type"],"backgroundTag":"unsupported-content-type","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}