I have an issue with exporting a module in Node.js. Here is a part of my code:
我在Node.js中导出模块时遇到问题。这是我的代码的一部分:
var zmq = require('zmq');
var module = require('module');
var DeviceRequester = function(port, name)
{
...
};
var SMValueGetter = function(socket)
{
...
};
module.exports.DeviceRequester = DeviceRequester;
module.exports.SMValueGetter = SMValueGetter;
When I use it I get the following error:
当我使用它时,我收到以下错误:
module.exports.DeviceRequester = DeviceRequester;
^
TypeError: Cannot set property 'DeviceRequester' of undefined
at Object.<anonymous> (<PROJECT_PATH>/node_modules/lse/lib/lse.js:168:32)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (<PROJECT_PATH>/server.js:6:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
I have no idea why it occurs. I've red the Node.js documentation and some tutorials about exporting modules and all of them do it that way. Am I overlooking something?
我不知道为什么会这样。我已经重新编写了Node.js文档和一些关于导出模块的教程,所有这些都是这样做的。我忽略了什么吗?
1 个解决方案
#1
3
Give more attentions at errors
更多关注错误
TypeError: Cannot set property 'DeviceRequester' of undefined
TypeError:无法设置未定义的属性“DeviceRequester”
at line var module=require("module");
you are overwriting the default module
variable.
at line var module = require(“module”);您正在覆盖默认模块变量。
simple try to change at something that makes more sense, such as
简单地尝试改变更有意义的东西,例如
var MyModule=require(..path..)
var MyModule = require(.. path ..)
#1
3
Give more attentions at errors
更多关注错误
TypeError: Cannot set property 'DeviceRequester' of undefined
TypeError:无法设置未定义的属性“DeviceRequester”
at line var module=require("module");
you are overwriting the default module
variable.
at line var module = require(“module”);您正在覆盖默认模块变量。
simple try to change at something that makes more sense, such as
简单地尝试改变更有意义的东西,例如
var MyModule=require(..path..)
var MyModule = require(.. path ..)