wzrd.in icon indicating copy to clipboard operation
wzrd.in copied to clipboard

Allow optional requires

Open stevenmhunt opened this issue 5 years ago • 1 comments

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 avatar Apr 10 '20 15:04 stevenmhunt

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.

stevenmhunt avatar Apr 13 '20 02:04 stevenmhunt