Conversation
Adding a `module` export makes rollup and webpack automatically use that package over the NodeJS one when importing it into a project.
|
is that actually what we want? the aim here is for this package to always be used in the browser and never in node |
|
@calvinmetcalf Of course. const randomBytes = require('randombytes')it will use the The thing is that if I build a web-app and I use NPM to install this dependency and I do: import randomBytes from 'randombytes'then, to my knowledge (and this thread) Rollup and Webpack would import the If I have a web-app which is an SPA hosted on a server unrelated to NodeJS, what will happen is that Rollup or Webpack, when bundling my JS, will start to polyfill native NodeJS functionality for me (like How I learned to do package.json is:
But please, correct me if I'm wrong, because I think there are a lot of confusing things related to import/require, webpack/rollup, web/browser/node, etc.etc. and it's difficult for most people to understand how everything works 100%. I'm probably wrong here or there. 😃 For me it's a lot of information I just picked up here and there, and no-where did I find one guide that explains all of this in an easy way. 😭 |
|
I believe that webpack honers the browser field, have you tested to see if this is actually a problem for you ? |
|
@calvinmetcalf I believe so yes. I'm using rollup in most cases though. I will check rollup and come back here to note on which entry it's picking up. |
Adding a
moduleexport makes rollup and webpack automatically use that package over the NodeJS one when importing it into a project.