nodejs / readable-stream

Node-core streams for userland
https://nodejs.org/api/stream.html
Other
1.03k stars 227 forks source link

TypeError related with Buffer on _stream_writable.js #292

Closed hkailantzis closed 2 years ago

hkailantzis commented 7 years ago

Hi there,

using browserify v12.0.0, I'm getting an error related with this module. In particular:

../node_modules/browserify/node_modules/readable-stream/lib/_stream_writable.js:295

Uncaught TypeError: function Buffer(arg) {
  if (!(this instanceof Buffer)) {
    // Avoid going through an ArgumentsAdaptorTrampol...<omitted>...
} is not a function
    at Function.from (native)
    at decodeChunk (http://localhost:8000/scripts/app.js:52558:20)
    at writeOrBuffer (http://localhost:8000/scripts/app.js:52568:13)
    at module.exports.Writable.write (http://localhost:8000/scripts/app.js:52526:11)
    at Stream.ondata (http://localhost:8000/scripts/app.js:53456:26)
    at Stream.EventEmitter.emit (http://localhost:8000/scripts/app.js:49868:17)
    at drain (http://localhost:8000/scripts/app.js:32772:16)
    at Stream.stream.resume (http://localhost:8000/scripts/app.js:32831:5)
    at http://localhost:8000/scripts/app.js:32570:16
    at Item.run (http://localhost:8000/scripts/app.js:50285:14)
    at drainQueue (http://localhost:8000/scripts/app.js:50255:42)

able to reproduce it with node 0.12.x and node 6.x. I see that v12.0.0 of Bfy, is using: readable-stream": "^2.0.2" in its package.json, if that helps. thanks!

calvinmetcalf commented 7 years ago

what version of readable streams is it ? and what exactly are you doing that is causing this are you running browserify or do you have browserifed code you are running somewhere else?

theAl commented 7 years ago

Experienced the same error and found following (dirty) quickfix:

Changed line 295 in actual master in file _stream_writable.js (link) chunk = Buffer.from(chunk, encoding); to chunk = new Buffer(chunk, encoding);.

hkailantzis commented 7 years ago

if it helps, we found that problem is not there when updating Browserify version to v14.4.0. The error for us is NOT happening during build time, but runtime and on dev environment only. Its on a specific user action.

mcollina commented 7 years ago

I think it might be specific to that version of browserify. I do not see how we can better support that. Version 12.0.0 was released on the 26th of October (https://github.com/substack/node-browserify/releases/tag/12.0.0)

Which version of readable-stream was present in your node_modules folder?

hkailantzis commented 7 years ago

@mcollina -> package.json says '1.1.14' apparently, which Browserify v12.0.0 doesn't seem to have defined in its package.json (its ^2.0.2). There are multiple dependencies of this module, everywhere in our codebase. gulp related modules mostly.

calvinmetcalf commented 7 years ago

@hkailantzis that's a really old version of readable streams, we just published 2.3.0

hkailantzis commented 7 years ago

I know. But I don't get why upgrading Browserify fixes the problem (our current version is not using 1.x.). @theAl , maybe can shed some light regarding when this is happening on your end ?