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 x不是一个文件中的函数,但它在另一个文件中工作?_Javascript_Node.js - Fatal编程技术网

Javascript x不是一个文件中的函数,但它在另一个文件中工作?

Javascript x不是一个文件中的函数,但它在另一个文件中工作?,javascript,node.js,Javascript,Node.js,我在一个名为helpers.js的文件中定义了名为send()的函数,如下所示: module.exports = { send: function (param1, param2, param3, param4) { //does something } } 我有另外两个文件,我正试图从中使用此函数,因此我在这两个文件中导入了如下文件: helpers = require("../modules/helpers"), 在其中一个文件中,我可以访问he

我在一个名为helpers.js的文件中定义了名为send()的函数,如下所示:

module.exports = {
  send: function (param1, param2, param3, param4) {
    //does something
  }
}
我有另外两个文件,我正试图从中使用此函数,因此我在这两个文件中导入了如下文件:

helpers             = require("../modules/helpers"),
在其中一个文件中,我可以访问
helpers.send(param1,param2,param3)
函数,而在另一个文件中,我始终可以访问
helpers.send,它不是一个函数

为什么我只能从一个文件而不能从另一个文件访问
send()
函数


谢谢你的帮助

不同的文件夹位置…那么“../modules/helpers”是有效的吗?在不起作用的文件中,helper和helper.send是什么?(通过添加断点或console.log)两个文件都位于同一文件夹中,因此路径应该可以工作,两个文件中的require语句也应该相同。可能是您正在其中一个文件中覆盖
send
函数。如果您执行类似于
helpers.send=null
的操作,它将抛出该错误。您能在此处包含所有代码吗?也许这与模块加载无关