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.

usage demo comes error: "TypeError: dest.on is not a function"

See original GitHub issue

I run the usage demo:

const yauzl = require("yauzl");

yauzl.open("./OMStarPS_npi.capacity_11.5.0.zip", {lazyEntries: true}, function(err, zipfile) {
  if (err) throw err;
  zipfile.readEntry();
  zipfile.on("entry", function(entry) {
    if (/\/$/.test(entry.fileName)) {
      // Directory file names end with '/'.
      // Note that entires for directories themselves are optional.
      // An entry's fileName implicitly requires its parent directories to exist.
      zipfile.readEntry();
    } else {
      // file entry
      zipfile.openReadStream(entry, function(err, readStream) {
        if (err) throw err;
        readStream.on("end", function() {
          zipfile.readEntry();
        });
        readStream.pipe('./');
      });
    }
  });
});

comes error:

_stream_readable.js:501
  dest.on('unpipe', onunpipe);
       ^

TypeError: dest.on is not a function
    at AssertByteCountStream.Readable.pipe (_stream_readable.js:501:8)
    at D:\node\www\test\test-unzip\yauzl.js:19:20
    at D:\node\www\test\test-unzip\node_modules\yauzl\index.js:575:7
    at D:\node\www\test\test-unzip\node_modules\yauzl\index.js:631:5
    at D:\node\www\test\test-unzip\node_modules\fd-slicer\index.js:32:7
    at FSReqWrap.wrapper [as oncomplete] (fs.js:682:17)

I just wanna unzip a zip file.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
thejoshwolfecommented, Aug 28, 2018

Ah, yeah. Sorry. That require call is confusing. I’ve updated it with a comment explaining how to translate that to be useful outside of yauzl’s source code directory structure.

I took another look at your code from the OP, and I don’t know why I didn’t see this before, but the problem is here:

readStream.pipe('./');

You have to pipe() into a stream, not a file path. In my example I linked above I make a file write stream here: https://github.com/thejoshwolfe/yauzl/blob/51010ce4e8c7e6345efe195e1b4150518f37b393/examples/unzip.js#L193 https://github.com/thejoshwolfe/yauzl/blob/51010ce4e8c7e6345efe195e1b4150518f37b393/examples/unzip.js#L196

There are lots of other kinds of streams you can pipe the file contents into.

1reaction
bi-kaicommented, Aug 27, 2018
PS D:\node\www\test\test-unzip> node -v
v8.11.1
PS D:\node\www\test\test-unzip> node .\yauzl.js
_stream_readable.js:582
  dest.on('unpipe', onunpipe);
       ^

TypeError: dest.on is not a function
    at AssertByteCountStream.Readable.pipe (_stream_readable.js:582:8)
    at D:\node\www\test\test-unzip\yauzl.js:19:20
    at D:\node\www\test\test-unzip\node_modules\yauzl\index.js:575:7
    at D:\node\www\test\test-unzip\node_modules\yauzl\index.js:631:5
    at D:\node\www\test\test-unzip\node_modules\fd-slicer\index.js:32:7
    at FSReqWrap.wrapper [as oncomplete] (fs.js:658:17)

what is the easiest way to unzip a zip file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does this mean: TypeError: dest.on is not a function
The error is happening in the pipe() method in readable-stream. dest is the name of the first argument to pipe() ; the fact...
Read more >
[Solved]-TypeError: dest.on is not a function-node.js
You want fs.createWriteStream(). fs.openSync() just returns a file descriptor. So it would be: k.stderr.pipe(fs.createWriteStream('/dev/ ...
Read more >
Getting Started with Gulp.js - Semaphore Tutorial
Learn how to set up and use Gulp.js, a task runner for Node.js based on ... To copy files, we only need to...
Read more >
Express multer middleware
Usage. Multer adds a body object and a file or files object to the request object. The body object contains the values of...
Read more >
Minifying Javascript Files Error dest.on is not a function
'use strict'; var gulp = require('gulp'), concat = require('gulp-concat'), uglify = require('gulp-uglify'), //I know the teacher has ...
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