How to investigate “Cannot find module X” coming from browserified bundles?

一世执手 提交于 2019-12-12 04:58:38

问题


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.



来源:https://stackoverflow.com/questions/45125042/how-to-investigate-cannot-find-module-x-coming-from-browserified-bundles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!