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");
我在一些npm模块中有这个代码,我能够要求一个文件,其绝对路径以字符串形式给出,但是当我对变量执行相同操作时,我收到以下错误:
undefined:688
console.log(!(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND';; throw e; }()));
Error: Cannot find module "."
,输出为:
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; }()));
出了什么问题?为什么会这样?