简体   繁体   English

找不到模块'socket.io/node_modules/redis'

[英]Cannot find module 'socket.io/node_modules/redis'

When trying to do 当试图做

var redis = require('socket.io/node_modules/redis');

I get the error "Cannot find module 'socket.io/node_modules/redis" and I can't figure out why. 我收到错误“无法找到模块'socket.io/node_modules/redis”,我无法弄清楚原因。 I am running windows and ran "npm install socket.io" 我正在运行Windows并运行“npm install socket.io”

It seems like the same issue here: Error: Cannot find module 'socket.io/node_modules/redis' but the redis server is up and running. 这似乎是同样的问题: 错误:无法找到模块'socket.io/node_modules/redis'但redis服务器已启动并正在运行。

In my "socket.io/node_modules" folder I don't see anything Redis related. 在我的“socket.io/node_modules”文件夹中,我没有看到任何与Redis相关的内容。

The socket.io package.json doesn't show a dependency on redis: socket.io package.json没有显示对redis的依赖:

  "dependencies": {
    "engine.io": "Automattic/engine.io#15afd3",
    "socket.io-parser": "2.2.1",
    "socket.io-client": "Automattic/socket.io-client#05c9632",
    "socket.io-adapter": "0.2.0",
    "has-binary-data": "0.1.3",
    "debug": "0.7.4"
  }

Either way, theres no need to directly depend on another library's dependencies. 无论哪种方式,都不需要直接依赖于另一个库的依赖项。 If you need to use redis in your code, you can install redis and add it to your package.json using: 如果您需要在代码中使用redis ,可以使用以下命令安装redis并将其添加到package.json

npm install redis --save

and require like: 并要求:

var redis = require('redis');

It seems that you're using Socket.IO 1.0. 看来你正在使用Socket.IO 1.0。 Since 1.0 there is no more redis dependency. 从1.0开始,不再有redis依赖。 You can follow @go-oleg's recommendation and install redis package on your own. 您可以按照@ go-oleg的建议自行安装redis软件包。

Rather run 而是运行

npm install socket.io-redis --save npm install socket.io-redis --save

This will install this npm package. 这将安装此npm包。 I used this and it worked. 我用过这个并且有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM