browserify / browser-resolve

resolve function which support the browser field in package.json
MIT License
102 stars 70 forks source link

'process is not defined' when using process as a global #99

Closed kevinramharak closed 3 years ago

kevinramharak commented 3 years ago

https://github.com/browserify/browser-resolve/blob/master/index.js#L11 uses the global process. Im not sure if this is intended but this crashes my bundle at runtime because process is not defined. I do have the fs, path and process shimmed but that only replaces the imports not the variable reference.

I propose to add an explicit require to support this case:

var process = require('process');
kevinramharak commented 3 years ago

Well my PR would fix it in this wrapper, but the resolve pacakge requires something like rollup-plugin-node-globals anyway. Since that package is not made with the browser in mind i'll leave it up to you guys if this should be merged

ljharb commented 3 years ago

process is a node core module, so any properly functioning node module bundler will provide a shim for it.

If rollup (like webpack 5) fails to do this by default, I'd file a bug.

kevinramharak commented 3 years ago

This issue is not about the module process but about the usage of the global process. I indeed fixed it with a plugin that looks for usages of these globals and replaces them with references to my supplied shim. Since this is a widely used pattern in the ecosystem this PR is pointless. I do find it ironic that if everyone used require('process') instead of relying on global variables this pattern would have looked differnt.

ljharb commented 3 years ago

Right. I'm saying the global itself (all node globals) must be polyfilled by a node module bundler, or else the bundler is broken.

kevinramharak commented 3 years ago

Ah like that. Yeah with some extra configuration i managed to work it out.