let path = "/var/www/backend/src/foo";
console.log("a", path, require("/var/www/backend/src/foo"));
console.log("b");
console.log(require(path)); // throws an error
console.log("c");
I have this code inside some npm module, I am able to require a file with absolute path given as string, but when I do the same with a variable, I get the following error:
undefined:688
console.log(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND';; throw e; }()));
Error: Cannot find module "."
and the output is:
a /var/www/backend/src/foo { default: [Function: foo] }
b
undefined:688
console.log(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND';; throw e; }()));
What's wrong? Why is that so?