javascript Node.JS 对象原型在 Redis 中只能是一个 Object 或 null
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30426420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.JS object prototype may only be an Object or null with Redis
提问by user295583058
I've been trying to setup redis for my Node.JS API and I've been getting this error:
我一直在尝试为我的 Node.JS API 设置 redis,但我收到了这个错误:
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.
config 只是一个带有配置对象的 require('config') 文件。
采纳答案by user295583058
I figured out the issue. I had a global variable called Error
which conflicted with redis, and also some other dependencies.
我想通了这个问题。我有一个名为的全局变量Error
,它与 redis 以及其他一些依赖项发生冲突。
I fixed it by simply re-naming Error
to Errors
.
我通过简单地重新命名Error
为Errors
.
回答by T.J. Crowder
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
).
问题superCtor.prototype
是undefined
。唯一有效的第一个参数Object.create
是null
或非null
对象引用;您不能使用原语(包括undefined
)。
We can't say whysuperCtor.prototype
is undefined from the code you've quoted, but that's the problem with the Object.create
call.
我们无法从您引用的代码中说明为什么superCtor.prototype
未定义,但这就是Object.create
调用的问题。