nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.68k stars 29.1k forks source link

ERR_INTERNAL_ASSERTION - Exporting CSV with nestjs, express and json2csv #40299

Closed hardcodemike closed 3 months ago

hardcodemike commented 2 years ago

Version

v14.17.5

Platform

Microsoft Windows NT 10.0.19043.0 x64

Subsystem

No response

What steps will reproduce the bug?

When exporting a csv with nest using only nest, express and json2csv. If need I can provide the code snippet.

How often does it reproduce? Is there a required condition?

It happens everytime. No special condition.

What is the expected behavior?

Send via Http the exported CSV without any erros.

What do you see instead?

Exporting the CSV via Http but got and Error:

backend-nestjs_1 | Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals. backend-nestjs_1 | Please open an issue with this stack trace at https://github.com/nodejs/node/issues backend-nestjs_1 | backend-nestjs_1 | at new NodeError (node:internal/errors:278:15) backend-nestjs_1 | at assert (node:internal/assert:14:11) backend-nestjs_1 | at ServerResponse.detachSocket (node:_http_server:243:3) backend-nestjs_1 | at resOnFinish (node:_http_server:812:7) backend-nestjs_1 | at ServerResponse.emit (node:events:376:20) backend-nestjs_1 | at onFinish (node:_http_outgoing:800:10) backend-nestjs_1 | at callback (node:internal/streams/writable:550:21) backend-nestjs_1 | at afterWrite (node:internal/streams/writable:496:5) backend-nestjs_1 | at afterWriteTick (node:internal/streams/writable:483:10) backend-nestjs_1 | at processTicksAndRejections (node:internal/process/task_queues:79:21)

Additional information

Feel free to contact me if you need anything else. This is the codesnippet that will reproduce the error:

    @Post('export')
    async export(@Res() res: Response){
        const parser = new Parser({
            fields: ['ID', 'Name', 'Email', 'Product Title', 'Price', 'Quantity']
        });

        const orders = await this.orderService.all(['order_items']);

        const json = [];
        orders.forEach((order: Order) => {
            json.push({
                ID: order.id,
                Name: order.name,
                Email: order.email,
                'Product Title': '',
                Price: '',
                Quantity: ''
            });

            order.order_items.forEach((item: OrderItem) => {
                json.push({
                    ID: '',
                    Name: '',
                    Email: '',
                    'Product Title': item.product_title,
                    Price: item.price,
                    Quantity: item.quantity
                });
            })
        });

        const csv = parser.parse(json);

        res.header('Content-Type', 'text/csv');
        res.attachment('orders.csv');
        return res.send(csv);
    }
agiratech-chandru commented 1 year ago

service function also please post here

RedYetiDev commented 3 months ago

By any chance could you (A) provide a snippet without any dependencies (B) let me know whether this issue is still occurring in the latest version Node.js?

hardcodemike commented 3 months ago

It is not occurring anymore. Thanks for asking.

RedYetiDev commented 3 months ago

@ZoomGr if you are experiencing similar issues, please open an issue in the nodejs/help repository without any dependencies. If you cannot reproduce this without a specific dependency, please reach out to the dependency maintainer.