user295583058
user295583058

Reputation: 104

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.

Upvotes: 4

Views: 13028

Answers (2)

user295583058
user295583058

Reputation: 104

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.

Upvotes: 2

T.J. Crowder
T.J. Crowder

Reputation: 1074038

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.

Upvotes: 7

Related Questions