简体   繁体   English

Node.JS对象原型可能只是一个Object,或者使用Redis为null

[英]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: 我一直在尝试为我的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')文件。

The problem is that superCtor.prototype is undefined . 问题是superCtor.prototype undefined The only valid first argument to Object.create is either null or a non- null object reference; Object.create唯一有效的第一个参数是null或非null对象引用; you can't use primitives (including undefined ). 你不能使用原语(包括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. 我们不能说为什么从你引用的代码中未定义superCtor.prototype ,但这是Object.create调用的问题。

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来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行dyson模拟服务器(使用express.js)的异常“ TypeError:对象原型只能是对象或为空” - Exception 'TypeError: Object prototype may only be an Object or null' running dyson mock server (using express.js) 未捕获的TypeError:对象原型可能只是一个Object,或者在ember.js上为null - Uncaught TypeError: Object prototype may only be an Object or null on ember.js TypeScript错误对象原型只能是一个对象或null:未定义 - TypeScript Error Object prototype may only be an Object or null: undefined 未捕获的TypeError:Symfony 2中的ExtJS对象原型只能是Object或为null - Uncaught TypeError: Object prototype may only be an Object or null with ExtJS in Symfony 2 未捕获的类型错误:Object 原型可能只是 Object 或 null:未定义 - Uncaught TypeError: Object prototype may only be an Object or null: undefined TypeError: Object prototype may only be an Object or null: undefined - TypeError: Object prototype may only be an Object or null: undefined 对象原型无法在Node.JS中工作 - Object prototype not working in Node.JS node.js:了解对象原型 - node.js: Understanding object prototype Node.JS:调试以了解一个对象的原型名称 - Node.JS: debug to know one object's prototype name Node.js在原型内更改Number对象的值 - Node.js change Number object value inside prototype
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM