本文介绍: 遇到这个错误,上代码import thenFs fromthen-fsfunction 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.readFi..

遇到这个错误,上代码

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() {…..

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

即可

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注