Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打字稿';导出分配不能与其他导出元素一起在模块中使用';_Javascript_Node.js_Typescript_Node Modules - Fatal编程技术网

Javascript 打字稿';导出分配不能与其他导出元素一起在模块中使用';

Javascript 打字稿';导出分配不能与其他导出元素一起在模块中使用';,javascript,node.js,typescript,node-modules,Javascript,Node.js,Typescript,Node Modules,我的目标是为整个代码中的所有redis操作创建一个redis.js文件,就像下面的代码片段一样 const Redis = require('./handler/redis.js'); Redis.set(); Redis.get() etc .. from my app.js require('./core/redis')(redisClient); 上面的代码运行时没有任何错误,但我得到了typescript错误,因为“导出分配不能在具有其他导出元素的模块中使用” module.expo

我的目标是为整个代码中的所有redis操作创建一个redis.js文件,就像下面的代码片段一样

const Redis = require('./handler/redis.js');
Redis.set();
Redis.get() etc ..

from my app.js
require('./core/redis')(redisClient);
上面的代码运行时没有任何错误,但我得到了typescript错误,因为“导出分配不能在具有其他导出元素的模块中使用”

module.exports = function(redisClient) {

redisClient.on('error',function(err) {
    console.log('Redis Error ' + err);
});

redisClient.on('connected',function() {
    console.log('Redis Connected');
});

module.exports.set = function(key, value, next) {
    redisClient.set(key,value,next);
};

module.exports.get = function(key, next) {
    redisClient.get(key,next);
};

module.exports.del = function(key, next) {
    redisClient.del(key,next);
};
};
即使有这个警告,我的代码是如何运行的

编辑代码: //从我的app.js require('./core/redis').init(redisClient)


这是您编写的
module.exports=function(redisClient)的正确方法吗{
as assignment statement for
从此模块导出
,然后使用
module.exports.set
module.exports.get
module.exports.del>覆盖此语句,这就是它给出错误的原因“导出分配不能在具有其他导出元素的模块中使用”。我不知道从何处获取函数的
redisClient
参数。如果此参数在当前模块中已可用,则只需将代码编写为

redisClient.on('error',function(err) {
    console.log('Redis Error ' + err);
});

redisClient.on('connected',function() {
    console.log('Redis Connected');
});

module.exports.set = function(key, value, next) {
    redisClient.set(key,value,next);
};

module.exports.get = function(key, next) {
    redisClient.get(key,next);
};

module.exports.del = function(key, next) {
    redisClient.del(key,next);
};

您的模块有一个导出分配和其他导出元素。@DaveNewton我不明白您在这里想说什么,您能帮我提供一些链接或向我详细解释一下吗?您有一个
exports=
。您有“exports.foo=”。第一个是导出分配。其余是其他导出元素。@DaveNewton什么应该更改吗?如上所述,我想为所有操作维护一个单独的文件,还是让它像bcoz一样运行我的代码来解释问题,但我实际上是从另一个文件发送redisClient!我还想知道它是否比!
redisClient.on('error',function(err) {
    console.log('Redis Error ' + err);
});

redisClient.on('connected',function() {
    console.log('Redis Connected');
});

module.exports.set = function(key, value, next) {
    redisClient.set(key,value,next);
};

module.exports.get = function(key, next) {
    redisClient.get(key,next);
};

module.exports.del = function(key, next) {
    redisClient.del(key,next);
};