前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Cannot find module 'socket.io'

Cannot find module 'socket.io'

作者头像
hbbliyong
发布2018-03-06 11:20:46
1.3K0
发布2018-03-06 11:20:46
举报
文章被收录于专栏:hbbliyonghbbliyong
代码语言:javascript
复制
That's all. Then I try to use socket.io with this line:

var io = require('socket.io').listen(app);
And it output an error:

Error: Cannot find module 'socket.io'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (F:\nodejs\chat.js:8:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

I've tried all suggested method like cleaning cache, reinstalling nodejs or changing socket.io module path. Unfortunately, all of those solutions didn't solve this problem.

This terrible error killed my whole day. I greatly appreciate any help.

解决方法:

Try to execute npm install socket.io in the folder where your node.js file is (where you require the module). npm creates a folder node_modules wherever you execute npm install socket.io and you probably didn't do this in the correct folder.

npm install supervisor -g did work because -g is the global flag and you can basically do that anywhere.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-07-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档