Using stream or any Node.js library in a Node-Browser(Isomorphic) library

I am working on a Node-Browser (Isomorphic) library where the source code is written in TypeScript and transpiled into CJS and ES modules.
The transpiled code is shipped as is and not bundled using a module bundler before publishing.

I need to use the stream module from node core and I plan to use the stream-browserify package for the browser part.

  1. What is the best way to include the use of Node.js stream or any node specific library in the library?
  2. How can I include stream-browserify without having to rewrite the same code or with minimum duplication?
  3. I came across some examples where the browser field in package.json is used as follows –
   "browser" : {
       "stream":"stream-browserify";
   } 

How does this work?

28 thoughts on “Using stream or any Node.js library in a Node-Browser(Isomorphic) library”

Leave a Comment