I need to add Redis to nodejs But it cannot be executed smoothly
Using the redis version, same code, but getting this error:
my code:
import { createClient } from 'redis'
export const client = createClient({
socket: {
host: "localhost",
port: 6379
},
});
await client.connect();
console.log("client.isOpen: " + client.isOpen)
error:
socket.js:199 Uncaught (in promise) TypeError: net.connect is not a function
at RedisSocket._RedisSocket_createNetSocket (socket.js:199:17)
at eval (socket.js:175:346)
at new Promise (<anonymous>)
at RedisSocket._RedisSocket_createSocket (socket.js:171:10)
at RedisSocket._RedisSocket_connect (socket.js:148:148)
at RedisSocket.connect (socket.js:55:92)
at Commander.connect (index.js:196:66)
at eval (index.js:10:1)
at __webpack_require__.a (app.js:814:13)
at eval (index.js:1:21)
my package.json:
"dependencies": {
"-": "^0.0.1",
"axios": "^1.6.3",
"connect-redis": "^7.1.0",
"core-js": "^3.8.3",
"crypto-browserify": "^3.12.0",
"dayjs": "^1.11.10",
"for": "^0.0.1-dev.0",
"install": "^0.13.0",
"net": "^1.0.2",
"node-polyfill-webpack-plugin": "^3.0.0",
"node-redis": "^0.1.7",
"redis": "^4.6.12",
"stream-browserify": "^3.0.0",
"tls": "^0.0.1",
"url": "^0.11.3",
"util": "^0.12.5",
"vue": "^3.2.13",
"vue-router": "^4.2.5"
},
plead for help
use redis 3.1.2 but net.is-ip is not a Function
Node redis relies on a core
netlibrary from nodejs.Here is documentation
By installing an npm library
"net": "^1.0.2"you are replacing the underlying core library with another one. Not sure why do you even install this library, it's clearly outdated, last published 10 years ago.In general just remove this dependency from your package.json, rerun the npm install and it should fix your issues with redis.
Could you post the code using net library so we can address it instead? If it is necessary for your app, perhaps you should try using some dependency aliases. So that it does not have the same reserved core library name.
It seems to me like you didn't really understand how npm dependencies really work. As most of your dependencies are unnecessary.
-library has no code, just an empty module, you probably installed it by accidentconnect-redisrequiresexpress-sessionto be installed for it to work, so it's probably unused as wellforlibrary has no code either, when installed you only download a package.json pointing to non existent index fileinstalllibrary has some contents, I assume you installed it by accident as wellnode-polyfill-webpack-pluginis a webpack plugin, not sure how you plan on using it without webpacknode-redisis an old version ofredislibrary, you shouldn't be installing both, especially that you probably only useredisanywaytlsandnetobfuscate the core nodejs libraries