Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of require('util') in lib/ #356

Closed
mcollina opened this issue Aug 16, 2018 · 5 comments
Closed

Remove use of require('util') in lib/ #356

mcollina opened this issue Aug 16, 2018 · 5 comments

Comments

@mcollina
Copy link
Member

Because it's hard for browsers.

@mcollina
Copy link
Member Author

See #357 (comment) for more details.

@catamphetamine
Copy link

So, in the main file you have:
https://unpkg.com/readable-stream@3.0.6/readable.js

var Stream = require('stream');
if (process.env.READABLE_STREAM === 'disable' && Stream) {
  module.exports = Stream;
  exports = module.exports = Stream.Readable;
  exports.Readable = Stream.Readable;
  exports.Writable = Stream.Writable;
  exports.Duplex = Stream.Duplex;
  exports.Transform = Stream.Transform;
  exports.PassThrough = Stream.PassThrough;
  exports.Stream = Stream;
} else {
  exports = module.exports = require('./lib/_stream_readable.js');
  exports.Stream = Stream || exports;
  exports.Readable = exports;
  exports.Writable = require('./lib/_stream_writable.js');
  exports.Duplex = require('./lib/_stream_duplex.js');
  exports.Transform = require('./lib/_stream_transform.js');
  exports.PassThrough = require('./lib/_stream_passthrough.js');
  exports.finished = require('./lib/internal/streams/end-of-stream.js');
  exports.pipeline = require('./lib/internal/streams/pipeline.js');
}

First, how is it supposed to not throw in a browser, because there's no "stream" package there.
Second, suppose it doesn't throw at require('stream') and executes the else statement.
Then it goes to ./lib/_stream_readable.js and sees this:

/*<replacement>*/
var debugUtil = require('util');
var debug = void 0;
if (debugUtil && debugUtil.debuglog) {
  debug = debugUtil.debuglog('stream');
} else {
  debug = function () {};
}
/*</replacement>*/

And now it throws because there's no 'util' module in a browser.
catamphetamine/read-excel-file#12

How does this all work in browsers?
Are you relying on bundlers to automatically substitute things like require('util') and require('stream') with their own magic?

@mcollina
Copy link
Member Author

mcollina commented Nov 2, 2018

This project always relied on bundlers.

@danm
Copy link

danm commented Apr 3, 2019

I'd be happy to pick this up @mcollina are there any updates before i get started?

@mcollina
Copy link
Member Author

mcollina commented Apr 3, 2019

Nope. You'll need to work in https://github.com/nodejs/readable-stream/tree/master/build so when pulling from core the util dependencies are replaced correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants