Javascript 无法设置属性';出口';未定义的
我完全不知道node.js为什么让包含来自其他文件的文件变得如此困难 我有一个名为file_handler.js的文件Javascript 无法设置属性';出口';未定义的,javascript,node.js,intern,Javascript,Node.js,Intern,我完全不知道node.js为什么让包含来自其他文件的文件变得如此困难 我有一个名为file_handler.js的文件 exports = {}; exports = { upload_file: function (fileUploaderPath, filename) { var child_process = require('intern/dojo/node!child_process'); child_process.spawn(fileUplo
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(),我得到了一个“undefined不是函数”。我尝试了module.exports={…}和exports={…}的组合。模块和导出甚至没有在我的文件_handler.js中定义,所以我必须设置exports={};这对我来说毫无意义,因为Google上99%的示例都使用内置的module.exports。它应该是:
module.exports = {
upload_file: function (fileUploaderPath, filename) {
var child_process = require('intern/dojo/node!child_process');
child_process.spawn(fileUploaderPath + ' ' + filename);
}
};
我刚刚试过这个,效果很好
或者,您可以执行以下操作:
exports.upload_file=function (fileUploaderPath, filename) {
var child_process = require('intern/dojo/node!child_process');
child_process.spawn(fileUploaderPath + ' ' + filename);
};
应该是:
module.exports = {
upload_file: function (fileUploaderPath, filename) {
var child_process = require('intern/dojo/node!child_process');
child_process.spawn(fileUploaderPath + ' ' + filename);
}
};
我刚刚试过这个,效果很好
或者,您可以执行以下操作:
exports.upload_file=function (fileUploaderPath, filename) {
var child_process = require('intern/dojo/node!child_process');
child_process.spawn(fileUploaderPath + ' ' + filename);
};
好的,显然是因为我需要把它作为AMD模块加载 module.exports={…}是常用的JS方式
定义(函数(){…});是AMD的方式(我需要使用)。好的,显然是因为我需要将其作为AMD模块加载 module.exports={…}是常用的JS方式
定义(函数(){…});是AMD的方式(我需要使用)。是的,我试过了,但当我运行代码时,它说模块未定义(第一个示例),导出未定义(第二个示例)。是的,我试过了,但当我运行代码时,它说模块未定义(第一个示例),第二个示例中未定义导出。是否可以显示整个
文件\u handler.js
文件,或者至少显示它的开始和结束方式?是否可以显示整个文件\u handler.js
文件,或者至少它是如何开始和结束的?你能提供一个完整的例子来使用define
来上传文件吗?你能提供一个完整的例子来使用define
来上传文件吗?