Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot Read Properties of undefined (reading 'map') when headers aren't provided #102

Open
ondrovic opened this issue Sep 26, 2023 · 1 comment

Comments

@ondrovic
Copy link

ondrovic commented Sep 26, 2023

Headers are optional but in certain instances throws the following error

TypeError: Cannot read properties of undefined (reading 'map')
    at ObjectCsvStringifier.getRecordAsArray (C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\src\lib\csv-stringifiers\object.ts:21:30)
    at C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\src\lib\csv-stringifiers\abstract.ts:20:77
    at Function.from (<anonymous>)
    at ObjectCsvStringifier.CsvStringifier.stringifyRecords (C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\src\lib\csv-stringifiers\abstract.ts:20:32)
    at CsvWriter.<anonymous> (C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\src\lib\csv-writer.ts:17:51)
    at step (C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\dist\lib\csv-writer.js:33:23)
    at Object.next (C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\dist\lib\csv-writer.js:14:53)
    at C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\dist\lib\csv-writer.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\ondro\source\git\test-csv-writer\node_modules\csv-writer\dist\lib\csv-writer.js:4:12)

Code Sandbox Here, if not sure if it's a bug in my setup or something else, but would be nice to not have to include a header.

@RomanticGirl
Copy link

interface ObjectCsvWriterParams {
    path: string;
    header: ObjectStringifierHeader;
    fieldDelimiter?: string;
    recordDelimiter?: string;
    headerIdDelimiter?: string;
    alwaysQuote?: boolean;
    encoding?: string;
    append?: boolean;
}

use another API with optional header. It's not a bug.

interface ArrayCsvWriterParams {
    path: string;
    header?: string[];
    fieldDelimiter?: string;
    recordDelimiter?: string;
    alwaysQuote?: boolean;
    encoding?: string;
    append?: boolean;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants