【问题标题】:error UNHANDLED REJECTION ENOENT: no such file or directory, open '/vercel/path0/.cache/json/错误 UNHANDLED REJECTION ENOENT: 没有这样的文件或目录,打开 '/vercel/path0/.cache/json/
【发布时间】:2021-12-30 19:18:24
【问题描述】:

我在 for 循环中运行一个获取请求,我获取的 API 是一个 Heroku 服务器,它抓取数据并使用 res.json() 将其发送回。 heroku 服务器是免费版本。 gatsby-node (async createPages) 中失败的代码如下所示


const laro = await graphql(`{
 links {
  results 
  }
}
`)

await laro.data.links.results.forEach( async kok => {
   try {
   let luca = await kok.split("/")[4]
   let rollot = await fetch(
   `https://sheltered-meadow-66603.herokuapp.com/noti/${luca}`)

 await createPage({
 path: `/${luca}/`,
 component: abruNews,
 context: {
 data: rollot,
 },
})
} catch (err) {
  console.log(err)
}
})

我得到的错误是这样的

For more info and debugging tips: see https://gatsby.dev/sync-actions
File /vercel/path0/gatsby-node.js:232:14
230 | )
231 |
> 232 | return createPage({
| ^
233 | path: `/${luca}/`,
234 | component: abruNews,
235 | context: {
success Building production JavaScript and CSS bundles - 48.439s
success Rewriting compilation hashes - 0.001s
error UNHANDLED REJECTION ENOENT: no such file or directory, open '/vercel/path0/.cache/json/_abruzzo-esperienziale-un-viaggio-nei-cinque-sensi-nelle-terre-dei-briganti_.json'
Error: ENOENT: no such file or directory, open '/vercel/path0/.cache/json/_abr uzzo-esperienziale-un-viaggio-nei-cinque-sensi-nelle-terre-dei-briganti_.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-default@0.1.0 build: `gatsby build`
npm ERR! Exit status 1
npm ERR!

如果你能帮忙,谢谢

【问题讨论】:

标签: javascript node.js json heroku gatsby


【解决方案1】:

for 循环(而不是 forEach)似乎更好地结束每个请求并且错误消失了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 2019-01-26
    • 2021-06-08
    • 2021-10-21
    • 2019-06-24
    • 2016-07-05
    • 2013-02-04
    相关资源
    最近更新 更多