Re: Weird problems with module.exports

47 views
Skip to first unread message

Sitnin

unread,
Sep 7, 2012, 2:57:44 AM9/7/12
to nod...@googlegroups.com
I have two ideas:

1) try to use exports, not module.exports. Here is the difference: http://www.hacksparrow.com/node-js-exports-vs-module-exports.html

2) I encountered similar problem when testing my code with invalid environment. I had a Makefile which was running mocha tests but doesn't set proper working directory and environment variables for the Node so it can't load my modules. Maybe you could investigate in that direction.

Mariusz Nowak

unread,
Sep 7, 2012, 4:14:27 AM9/7/12
to nod...@googlegroups.com
Within Node.js such issue may occur *only* when your dealing with cyclic dependencies. If it's the case just move require's to modules in question to end of the file (after assignment to module.exports), it will fix that.

You say it's Travis error, so maybe it's the case of circular dependencies between packages? See this issue: https://github.com/isaacs/npm/issues/2063 there's also solution for that.

If it's none of the above, then either you misinterpreted something, or your modules are not loaded natively by Node but not in a compliant way by some other stuff in the middle, that could be the only explanation.


On Thursday, September 6, 2012 1:01:09 PM UTC+2, Andreas Richter wrote:
One of my modules was using:

module.exports = { loadModules: loadModules, initModules: initModules, eventRouteModules: eventRouteModules, notifyDependenciesOfInit: notifyDependenciesOfInit,
notifyDependenciesOfRoute: notifyDependenciesOfRoute, registerDependencies: registerDependencies, loadAbout: loadAbout };

instead of:

module.exports.loadModules = loadModules;
module.exports.initModules = initModules;
module.exports.eventRouteModules = eventRouteModules;
module.exports.notifyDependenciesOfInit = notifyDependenciesOfInit;
module.exports.notifyDependenciesOfRoute = notifyDependenciesOfRoute;
module.exports.registerDependencies = registerDependencies;
module.exports.loadAbout = loadAbout;

Seems harmless and worked pretty much 99% of the time. However when running mocha on TravisCI it would fail saying it couldn't find loadAbout.
I tried many different things and could not narrow it down to anything else but this change. The issue occurs both on node 0.6 and 0.8 based versions.
Locally I tested the same variations on Mac OS and ubuntu and they did not show the problem.

Does anyone have any ideas why this would cause problems on some platforms?
Reply all
Reply to author
Forward
0 new messages