oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.26k stars 2.77k forks source link

TypeError: source.on is not a function. (In 'source.on("error", emit)', 'source.on' is undefined) #2743

Open lumenwrites opened 1 year ago

lumenwrites commented 1 year ago

What version of Bun is running?

0.5.9

What platform is your computer?

Darwin 20.6.0 x86_64 i386

What steps can reproduce the bug?

Install a zip-a-folder package:

bun i zip-a-folder

Use it in a script to zip a folder:

import { zip } from 'zip-a-folder'
[...]
await zip(SOURCE_FOLDER, OUTPUT_FILE_PATH)

Same issue with archiver package.

What is the expected behavior?

Everything works (like it does with regular node.js)

What do you see instead?

This error:

27 |   PassThrough.call(this, options);
28 | 
29 |   beforeFirstCall(this, '_read', function() {
30 |     var source = fn.call(this, options);
31 |     var emit = this.emit.bind(this, 'error');
32 |     source.on('error', emit);
        ^
TypeError: source.on is not a function. (In 'source.on("error", emit)', 'source.on' is undefined)
      at /Users/ray/projects/GDSchool/preprocess-course-bun/node_modules/lazystream/lib/lazystream.js:32:4
      at /Users/ray/projects/GDSchool/preprocess-course-bun/node_modules/lazystream/lib/lazystream.js:18:4
      at /Users/ray/projects/GDSchool/preprocess-course-bun/node_modules/lazystream/node_modules/readable-stream/lib/_stream_readable.js:443:4
      at resume_ (/Users/ray/projects/GDSchool/preprocess-course-bun/node_modules/lazystream/node_modules/readable-stream/lib/_stream_readable.js:790:4)

Additional information

No response

Jarred-Sumner commented 1 year ago

we should investigate forcing readable-stream to use bun's internal version of this package

Electroid commented 1 year ago

Newest error using Bun v1.0.7. is:

❯ cat zip.js
import { zip } from 'zip-a-folder'
await zip("./demo", "./demo.zip");
❯ mkdir demo
❯ bun zip.js 
SyntaxError: Indirectly exported binding name 'unescape' is not found.
sean256 commented 8 months ago

I just ran into this same error with the package form-data. I'm trying to use a ReadableStream with a multipart form (which Bun's FormData doesn't support)

bun 1.0.29

28 |   source.emit = function() {
29 |     delayedStream._handleEmit(arguments);
30 |     return realEmit.apply(source, arguments);
31 |   };
32 |
33 |   source.on('error', function() {});
       ^
TypeError: source.on is not a function. (In 'source.on("error", function() {
    })', 'source.on' is undefined)