Cannot find module 'socket.io/node_modules/red

2019-07-04 10:37发布

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. I am running windows and ran "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.

In my "socket.io/node_modules" folder I don't see anything Redis related.

3条回答
劫难
2楼-- · 2019-07-04 11:04

The socket.io package.json doesn't show a dependency on 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:

npm install redis --save

and require like:

var redis = require('redis');
查看更多
我只想做你的唯一
3楼-- · 2019-07-04 11:07

Rather run

npm install socket.io-redis --save

This will install this npm package. I used this and it worked.

查看更多
三岁会撩人
4楼-- · 2019-07-04 11:27

It seems that you're using Socket.IO 1.0. Since 1.0 there is no more redis dependency. You can follow @go-oleg's recommendation and install redis package on your own.

查看更多
登录 后发表回答