节点:套接字io require.resolve不是一个函数? [英] Node: Socket io require.resolve is not a function?
问题描述
我很惊讶谷歌搜索这个并没有给我任何结果。无论如何这里是我的问题,当使用 socket.io
:
I'm surprised that googling this does not give me any results. Anyway here's my problem when using socket.io
:
当我进一步检查时,它来自socket.io index.js源文件(第28行导致问题:
When I check further, it was from socket.io index.js source file (line 28) that's causing problem:
var clientSource = read(require.resolve('socket.io-client / socket.io.js' ),'utf-8');
所以require.resolve()不是函数,我怀疑起初它是我的节点版本但没有,我已更新到最新版本,它仍然存在。
So require.resolve() is not a function, I suspect at first it was my node version but no, I have updated to latest and it still persists.
我正在使用browserify和gulp生成应用程序文件。
I'm using browserify and gulp to generate the app file.
任何人都对此有所解决?谢谢
Anyone has a a fix on this? Thanks
推荐答案
browserify
执行 require
没有解决
方法。
因为显而易见的原因,你无法运行 socket.io
浏览器内的服务器。如果你真的想要一个socket.io客户端,你应该要求 socket.io-client
(自述文件说它与浏览器兼容)。
for obvious reasons, you can't run socket.io
server inside browser. If you really want a socket.io client, you should require socket.io-client
(readme says it is browserify-compatible).
这篇关于节点:套接字io require.resolve不是一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!