browserify / wzrd.in

browserify as a service.
http://wzrd.in
MIT License
637 stars 96 forks source link

Allow optional requires #203

Open stevenmhunt opened 4 years ago

stevenmhunt commented 4 years ago

I am attempting to use browserify-cdn to bundle the NPM module cucumber, however I receive the following error:

Error: "browserify exited with code 1"

code: 1
stderr: Error: Cannot find module 'graceful-fs' from '/tmp/cucumber120310-6085-1fs7afr.h95u/node_modules/cucumber/node_modules/mz'
at /home/wzrd/wzrd.in/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
at process (/home/wzrd/wzrd.in/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
at ondir (/home/wzrd/wzrd.in/node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
at load (/home/wzrd/wzrd.in/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
at onex (/home/wzrd/wzrd.in/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
at /home/wzrd/wzrd.in/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:153:21)

After further investigation, I identified the following lines of code within a dependency mz:

try {
  fs = require('graceful-fs')
} catch(err) {
  fs = require('fs')
}

Would it be possible to add the browserify-optional transform into browserify-cdn to support this situation? Perhaps there could be a flag to enable this as an optional configuration?

Alternatively the built-in ignoreMissing option may work for my use case. Would it be possible to add support to allow this option to be passed into the bundler?

stevenmhunt commented 4 years ago

Update: I was able to find browser-compatible copies of what I wanted, however I think the idea of allowing a way of setting ignoreMissing could still be useful.