Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS object prototype may only be an Object or null with Redis

I've been trying to setup redis for my Node.JS API and I've been getting this error:

util.js:634
  ctor.prototype = Object.create(superCtor.prototype, {
                          ^
TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (native)
    at Object.exports.inherits (util.js:634:27)
    at Object.<anonymous> (/home/<user>/<project>/node_modules/redis/lib/parser/javascript.js:31:6)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/<user>/<project>/node_modules/redis/index.js:33:14)

Here's my code:

console.log('Redis: ' + config.redis.host);
console.log('Redis: ' + config.redis.port);
console.log('Redis: ' + config.redis.pass);

redis       = require('redis');
redisClient = redis.createClient(
    config.redis.port, 
    config.redis.host, 
    {
        auth_pass: config.redis.pass
    }
);

config is simply a require('config') file with a config object.

like image 865
user295583058 Avatar asked Jan 09 '23 07:01

user295583058


2 Answers

The problem is that superCtor.prototype is undefined. The only valid first argument to Object.create is either null or a non-null object reference; you can't use primitives (including undefined).

We can't say why superCtor.prototype is undefined from the code you've quoted, but that's the problem with the Object.create call.

like image 65
T.J. Crowder Avatar answered Jan 10 '23 21:01

T.J. Crowder


I figured out the issue. I had a global variable called Error which conflicted with redis, and also some other dependencies.

I fixed it by simply re-naming Error to Errors.

like image 20
user295583058 Avatar answered Jan 10 '23 21:01

user295583058