I m running a fetch request inside of a for loop, the API I'm fetching it's a heroku server that scrapes data and sends it back with res.json(). The heroku server is a free version. The code failing in the gatsby-node (async createPages) is shown down below
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)
}
})
the error I'm getting is this
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!
Thanks if you can help
A for loop (instead of a forEach) seems to be better ending every request and the error disappeared