I recently worked on an npm package that is supposed to be consumed on both Node.js environment and the browser (using React/Angular/etc..).

Things started getting complicated when the node branch of the code needed to require native Node.js packages — like fs.

#node 

How to Make Your Npm Package Work on Both Node.js and Browser
2.95 GEEK