Node.JS object prototype may only be an Object or null with Redis
12,126
Solution 1
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
.
Solution 2
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.
Author by
user295583058
Updated on June 04, 2022Comments
-
user295583058 almost 2 years
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.
-
T.J. Crowder almost 9 yearsYes, that makes sense -- and this is part of why global variables should be avoided whenever possible. FYI,
Error
is a standard JavaScript thing. -
user295583058 almost 9 yearsYes, I know that, which is why I changed it.
-
Артур Гудиев over 4 yearsWhat exactly did you rename?