question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App crashed after stream closed.

See original GitHub issue

Node: v8.9.4 (no bug on node v6.*) NPM: 5.6.0 Koa: v1.2.4/v2.5.0

Note: ctx already defined by Koa

import { Client } from 'pg';
import PgQueryStream from 'pg-query-stream';
import config from '../../config';

const pgDirectClient = new Client({
  user: config.db.username,
  host: config.db.host,
  database: config.db.databaseName,
  password: config.db.password,
  port: config.db.port,
});
pgDirectClient.connect();

const sqlQueryStream = pgDirectClient.query(new PgQueryStream("SELECT * FROM users"));
const fileFormat = 'xlsx';
const formatRow = row => [row.id, row.name];
const closeStream = ctx.end;
const sheetName = 'Sheet_1';
const headFields = ['id', 'name'];
const workbook = new exceljs.stream.xlsx.WorkbookWriter({
  stream: ctx.body,
  useStyles: false,
  useSharedStrings: false,
});

const sheet = workbook.addWorksheet(sheetName);
sheet.addRow(headFields).commit();

sqlQueryStream
      .on('data', (data) => {
        sheet.addRow(formatRow(data)).commit();
      });

sqlQueryStream
  .on('end', () => {
    workbook.commit().then(() => closeStream());
  });

OR

...
sqlQueryStream
  .on('end', () => {
    workbook.commit();
  });
  • Added console.log to all .on listeners for debug purpose.

Logs

npm run..server sqlQueryStream.on(data) (data.id=149)
npm run..server sqlQueryStream.on(end)
npm run..server workbook.stream.on('finish')
npm run..server TypeError: Cannot read property 'objectMode' of undefined
npm run..server     at module.exports.Readable.push (_stream_readable.js:195:14)
npm run..server     at module.exports.Duplex._destroy (_stream_duplex.js:104:8)
npm run..server     at module.exports.destroy (internal/streams/destroy.js:32:8)
npm run..server     at destroy (/usr/src/app/node_modules/destroy/index.js:41:12)
npm run..server     at listener (/usr/src/app/node_modules/on-finished/index.js:169:15)
npm run..server     at onFinish (/usr/src/app/node_modules/on-finished/index.js:100:5)
npm run..server     at callback (/usr/src/app/node_modules/ee-first/index.js:55:10)
npm run..server     at ServerResponse.onevent (/usr/src/app/node_modules/ee-first/index.js:93:5)
npm run..server     at emitNone (events.js:111:20)
npm run..server     at ServerResponse.emit (events.js:208:7)
npm run..server     at onFinish (_http_outgoing.js:723:10)
npm run..server     at afterWrite (_stream_writable.js:454:3)
npm run..server     at _combinedTickCallback (internal/process/next_tick.js:144:20)
npm run..server     at process._tickDomainCallback (internal/process/next_tick.js:218:9)

No results after research in exceljs issues, node issues, google and stackoverflow 😦

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
khawkinsoncommented, Mar 30, 2018

@safonovklim I use koa and struggled with this for awhile also and this worked for me:

const stream = new Stream.PassThrough();
const workbook = new Excel.stream.xlsx.WorkbookWriter({ stream });
 // do all you want to the workbook

await workbook.commit()
ctx.body = stream;
1reaction
rnzocommented, Mar 9, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

App crashing when I try to watch streams : r/Twitch - Reddit
Go to play store : Android system webview app. Update the app. It kept updating for me so I removed and after that...
Read more >
Apple Watch App Crashing | Apple Developer Forums
The Watch app crashes at the Share Settings screen. On occasion it says you need to verify your Apple details, but after entering...
Read more >
What to Do If Apps Keep Crashing on an Android Device
Force the problematic app to close · 1. Start the Settings app. · 2. Tap Apps & notifications. · 3. Find the crashing...
Read more >
Android crash when app is closed and reopened
When I close the app by pressing the HOME button, then try to open the app again, it crashes and I get the...
Read more >
xbox app crashes when starting to stream from xbox one
This might have occurred due to some corruptions in apps. I would suggest you to refer to the Microsoft Help Article given below...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found