Cannot find module 'socket.io/node_modules/red

2019-07-04 10:27发布

问题:

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.

回答1:

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');


回答2:

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.



回答3:

Rather run

npm install socket.io-redis --save

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