I have an api route in my next.js pages app (api/revalidate) for on demand revalidation of the data, and I have set a afterChange hook in a payload collection like this (
https://github.com/payloadcms/website-cms/blob/main/src/utilities/regeneratePage.ts).
When my next.js app is on dev server everything works, but when I build and serve the app it don't.
On the build I can go to the url for the revalidation and everything works fine, but for some reason payload can't.
Can someone help me? Thanks
I've just hit the same error. It's not on my NextJS FE as I can revalidate with Postman. Its some issue on the Payload side. Could be CORS or Node version maybe (18.16). My error from the payload logs is :
11:51:42] ERROR (payload): TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)
In my case it was a redirect on the front end URL that broke fetch (I didn't have redirect:follow set). I changed the URL and its working now.
The error message wasn't very helpful!!
I found this was a bug with the new fetch module in node. Going to node version 16 fixed this.
However, it seems ISR is quite buggy in the new app directory. Deployed to vercel I can get the home route "/" to revalidate but not any other page. But the other pages will revalidate when I run it on the root URL "/" but not the individual path like "about-us"
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.