我正在尝试在 NestJS 中使用 ExcelJS。由于某种原因,我无法打开 xlsx 文件。
exceljs 使用此代码检查文件是否存在
fs: {
exists: function exists(path) {
return new Promise(function (resolve) {
console.log(path);
fs.access(path, fs.constants.F_OK, function (err) {
resolve(!err);
});
});
}
},
Run Code Online (Sandbox Code Playgroud)
该代码返回无法读取未定义的属性“F_OK”。第 4 行的 Console.log 返回路径我正确发送
但是,如果我尝试使用此代码从我的服务访问相同的文件
fs.access(this.file, fs.constants.F_OK | fs.constants.W_OK, (err) => {
if (err) {
console.error(
`${this.file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
} else {
console.log(`${this.file} exists, and it is writable`);
}
});
Run Code Online (Sandbox Code Playgroud)
该代码返回“file.xlsx 存在,并且可写”。有什么区别以及为什么我无法使用 exceljs 读取同一文件?