I'm writing a program with several threads and a lot of requires. I need circular dependencies otherwise there will be too many files.
I have a function that can prevent it from looping, however node complains about it before it can even run. I've tried looking for a way, but its hard to find a "bypass" instead of moving a lot of stuff around.
Is it possible to disable the protections and let it run anyway?
Here's my code;
constants.js
// This should prevent any circular dependency but node shuts it down too eagerly.
function _getCallerFile() {
    // Returns the file that originally called.
    
    var err = new Error();
    Error.prepareStackTrace = (_, stack) => stack;
    Error.prepareStackTrace = undefined;
    return err.stack.toString();
}
var x = _getCallerFile();
console.log(x);
console.log(x.includes(".js"))
console.log(x.includes("threading.js"))
//if (!x.includes("input.js")) var input = require('./constants/input.js');
if (!x.includes("threading.js")) var threading = require('./constants/threading.js');
module.exports ={ 
    threading: threading
    //input: input
};
threading.js
var x = require('../constants.js');
module.exports.init = async function (whoami) {
    x.sendMsg("debug", whoami, `Starting!`);
}
index.js
var x = require('./constants.js');
async function main() { 
  x.threading.init(whoami);
}
main();
 
     
    