遇到这个错误,上代码:

import thenFs from 'then-fs'

function getAllFile() {
  const r1 = await thenFs.readFile('./file/1.txt', 'utf8')
  console.log(r1)
  const r2 = await thenFs.readFile('./file/1.txt', 'utf8')
  console.log(r2)
  const r3 = await thenFs.readFile('./file/1.txt', 'utf8')
  console.log(r3)
}

getAllFile()

代码块如上所示,真的找了很久的bug,一直都不明白这个是什么意思,也看到了不少的说是 ESlint的问题,node.js 默认支持 common.js and so on。

但是实际意义上,是我 async没加!对就是这个这么蠢得错法。无语了。

解决办法:

async function getAllFile() {.....

男默女泪,真的找了很久。。。

即可。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐