Jenny M Jenny M - 2 months ago 7
Javascript Question

Module export modules not working

I have the following code which need to export module based of some condition,

var spawnLinux = require('child-process').spawn;
var module2 = require('module_2');

var isWin = process.platform === 'win32';

module.exports = function spawn() {
if (isWin) {
return module_2;
} else {
return spawnLinux;

The problem is that module_2 is returning error when used by external module but if it used inside this specific module it runs OK, what can be the problem in the export?

If I use it like this (in diffrent module)

var module2 = require('module_2');; //this working

this is not working

var module2 = require('moduleBase);;//Here I got error


try this

var module2 = require('moduleBase)();;