【TypeScript】Argument of type ‘Buffer‘ is not assignable to parameter of type ‘string‘.

华宣
2023-12-01

当使用 fs.readFileSync 读取json文件,然后用 JSON.parse() 时,出现上述错误。正确的方法是加上 utf-8 参数:

const raw = fs.readFileSync(filepath, 'utf-8')
const donwloadObj = JSON.parse(raw)
 类似资料: