无法设置未定义的属性“ exports”

我完全不知道为什么node.js很难包含其他文件中的文件。

我有一个名为file_handler.js的文件

exports = {};
exports = {
    upload_file: function (fileUploaderPath, filename) {
        var child_process = require('intern/dojo/node!child_process');
        child_process.spawn(fileUploaderPath + ' ' + filename);
    }
};

我希望有类似的东西

var file_handler = require('./file_handler.js');
file_handler.upload_file(a,b);

上班。但是我为upload_file()得到了一个“未定义的不是函数”。我尝试了module.exports = {...}和export = {...}的组合。我的file_handler.js甚至都没有定义模块和导出,因此我必须设置export = {};。这对我来说毫无意义,因为Google上99%的示例都使用module.exports作为内置模块。

好的,显然是因为我需要将其作为AMD模块加载。

module.exports = {...}是CommonJS的方式。

define(function(){...}); 是AMD方式(我需要使用)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章