我在目录中有文件,let resolvers = { ...resolversArray[0], ...resolversArray[1] };
行的确被设置,但是我试图这样做,所以我不需要手动放入数组的每个项目。
这是我的代码
let resolversArray = [];
let promise = new Promise((resolve, reject) => {
fs.readdirSync(`${__dirname}/modules`).forEach((folder) => {
let temp = require(`./modules/${folder}/resolver.js`);
resolversArray[folder] = temp;
});
if (resolversArray.length > 0) {
resolve(resolversArray);
} else {
reject("Resolvers Array is empty");
}
});
promise.then((array) => {
console.log("returned array", resolversArray);
});
结果是我得到了拒绝承诺,但解析器数组被返回为空。