nodejs / readable-stream

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

browser support: use setTimeout instead of process.nextTick #480

Closed ashwinkumar6 closed 2 years ago

ashwinkumar6 commented 2 years ago

Describe the bug

I'm using the microphone-stream package which in turn uses this package

Consuming this API from the browser throws the following error

Error

Uncaught ReferenceError: process is not defined
    at maybeReadMore (_stream_readable.js:561:1)
    at addChunk (_stream_readable.js:306:1)
    at readableAddChunk (_stream_readable.js:280:1)
    at Readable.push (_stream_readable.js:241:1)
    at ScriptProcessorNode.recorderProcess (microphone-stream.js:108:1)

The error seems to be coming from the streamreadable.js file line561 `process.nextTick(maybeReadMore, stream, state);` I believe process.nextTick is a NodeJS specific API and isn't available on the browser. setTimeout should be used instead

Screenshots

Screen Shot 2022-07-19 at 2 31 21 PM Screen Shot 2022-07-19 at 2 31 35 PM

Your environment

OS: macOS Monterey (12.3.1) Node: 16.15.1

Version number

microphone-stream@6.0.1

Is the issue in the browser/Node.js?

Browser

Details of the browser/Node.js version

Chrome: 103.0.5060.134

mcollina commented 2 years ago

Here are the instructions to tell the transpiler how to deal with process and buffer: https://github.com/nodejs/readable-stream#usage-in-browsers