How to investigate “Cannot find module X” coming f

2019-08-20 05:54发布

问题:

Desperate mode: Tried many different configs and all failed. I have a browserified + babelified bundle called videomail-client.js here:

https://github.com/binarykitchen/videomail-client/tree/develop/dist

The package.json's main entry of that package is pointing to this file.

Now, when I require() that package from another project within and browserify it, then I see this error from the gulp task using browserify:

[16:26:32] Error: Cannot find module './keys' from '/home/michael-heuberger/code/videomail.io/node_modules/videomail-client/dist'
    at /home/michael-heuberger/code/videomail.io/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
    at load (/home/michael-heuberger/code/videomail.io/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (/home/michael-heuberger/code/videomail.io/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at /home/michael-heuberger/code/videomail.io/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:152:21)

Hmnmm, sounds complicated? Let me rephrase. Package videomail-client is browserified. Another project, videomail.io, is requiring it and browserifying all together over again with other packages. That's there it fails.

On a side note, when I run standalone examples using videomail-client.js, it works fine.

I think the problem is that browserify can't resolve the ./keys file. But it should be included in the browserified videomail-client.js package and resolved from there. How can I tell browserify to resolve it the correct way?

Suggestions welcome how I can investigate and fix this best. Thanks!!

回答1:

The solution has two steps: use browserify's standalone option and the gulp-derequire package. It works now.



回答2:

This sounds a lot like a problem I ran into a few years ago (and yes, it is tough to describe :) )

I never got an answer but maybe you'll have better luck. The solution I eventually went with was to not attempt to re-browserify already-browserified libraries; I ended up just concatenating it in and minifying the whole bundle afterwards.