【发布时间】: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!
如果你能帮忙,谢谢
【问题讨论】:
-
发出请求时您的服务器是否已启动?
-
是的主机出现sheltered-meadow-66603.herokuapp.com/1感谢您的帮助您是否遇到过类似的问题
标签: javascript node.js json heroku gatsby