Cannot find module 'socket.io'

简介: 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.
 
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.

目录
相关文章
|
Kubernetes Linux Shell
minikube安装kubernetes以及start启动报错解决办法:Unable to find image ‘gcr.io/k8s-minikube/kicbase
使用minikubu安装kuburnetes集群,所遇到的问题,以及如何设置。
1277 0
|
1月前
|
存储 Java 数据处理
|
1月前
|
Java API
java中IO与NIO有什么不同
java中IO与NIO有什么不同
|
3月前
|
存储 Java 数据安全/隐私保护
从零开始学习 Java:简单易懂的入门指南之IO字符流(三十一)
从零开始学习 Java:简单易懂的入门指南之IO字符流(三十一)
|
3月前
|
存储 移动开发 Java
从零开始学习 Java:简单易懂的入门指南之IO字节流(三十)
从零开始学习 Java:简单易懂的入门指南之IO字节流(三十)
|
3月前
|
存储 网络协议 Java
Java学习—IO流
Java学习—IO流
|
3月前
|
存储 Java Android开发
IO流:java中解码和编码出现乱码说明及代码实现
IO流:java中解码和编码出现乱码说明及代码实现
|
3月前
|
存储 算法 Java
从零开始学习 Java:简单易懂的入门指南之IO序列化、打印流、压缩流(三十三)
从零开始学习 Java:简单易懂的入门指南之IO序列化、打印流、压缩流(三十三)
|
3月前
|
缓存 Java API
IO流【IO流技术介绍、 IO流的经典写法、 IO流新语法经典写法、Java中流的概念细分 】(一)-全面详解(学习总结---从入门到深化)
IO流【IO流技术介绍、 IO流的经典写法、 IO流新语法经典写法、Java中流的概念细分 】(一)-全面详解(学习总结---从入门到深化)
43 0
|
3月前
|
分布式计算 Java 大数据
IO流【Java对象的序列化和反序列化、File类在IO中的作用、装饰器模式构建IO流体系、Apache commons-io工具包的使用】(四)-全面详解(学习总结---从入门到深化)
IO流【Java对象的序列化和反序列化、File类在IO中的作用、装饰器模式构建IO流体系、Apache commons-io工具包的使用】(四)-全面详解(学习总结---从入门到深化)
53 0