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

'error' event on JSON2CSVNodeTransform instance at: 'ERR_STREAM_WRITE_AFTER_END' #78

Open
hius74 opened this issue Oct 23, 2024 · 0 comments

Comments

@hius74
Copy link

hius74 commented Oct 23, 2024

I have an issue when I try to transform JSON into CSV records multiple times.

Package version: 7.0.6
Node version: v20.15.1
Whole code:

import {createWriteStream} from 'node:fs';
import { Transform } from '@json2csv/node';
import {Readable} from "node:stream";

(async () => {

    const input = new Readable({
        read() {},});

    const transform = new Transform();
    const output = createWriteStream('test.csv', { encoding: 'utf8' });

    input.pipe(transform).pipe(output);

    input.push(JSON.stringify({a: 1}))
    input.push(JSON.stringify({a: 2}))
})();

The error is

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at _write (node:internal/streams/writable:481:11)
    at Writable.write (node:internal/streams/writable:502:10)
    at Readable.ondata (node:internal/streams/readable:1007:22)
    at Readable.emit (node:events:519:28)
    at Readable.read (node:internal/streams/readable:780:10)
    at flow (node:internal/streams/readable:1281:53)
    at resume_ (node:internal/streams/readable:1260:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on JSON2CSVNodeTransform instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_STREAM_WRITE_AFTER_END'
}

Why I need multiple write? So, I would like to export AWS DynamoDB records into CSV. When I read records, AWS DynamoDB provide array of items and nextToken to continue read. To read all DynamoDB records I need multiple request untile DynamoDB record return nextToken = null

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

1 participant