Версия узла: 10.16.3
Я в замешательстве. Очевидно, fs.statSync
в следующем коде не является функцией ... Может кто-нибудь объяснить мне, почему следующий код вызывает эту ошибку?
fs.readFile('./config.json', 'utf8',
(error, config) => {
console.log(`1. ${config}`)
if (error) console.error(`Error: ${error}`)
else {
for (const archive of JSON.parse(config).archives){
console.log(`2. ${archive}`)
console.log(`3. ${fs.statSync(archive).isDirectory()}`)
}
}
}
)
Консоль
1. {
"archives": [
"C:\\Windows",
"C:\\AMD",
"C:\\MSOCache",
"C:\\PerfLogs",
"C:\\Program Files",
"C:\\Program Files (x86)",
"C:\\ProgramData",
"C:\\Users",
"C:\\WebDrivers"
]
}
2. C:\Windows
3. Uncaught TypeError: fs.statSync is not a function
at file-system.js:128
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61)