I have a website that pulls data from two servers. The blog API is currently dead, therefore the build fails because Next fails to generate static paths for /blog/[page]
. Is there a way to ignore or catch this error and build the website without the /blog
dynamic route when the blog API is not available?
Error: Export encountered errors on following paths:
/blog: /cs-cz/blog
/blog: /en-gb/blog
Or should I approach this problem from a different perspective? The obvious solution would be to fix the blog API, but I don’t have control over that. The blog API service has been unreliable in the past. The website should be able to build and update data without relying on the blog API.
I tried this:
export async function getStaticPaths() {
// ... fetch posts from api ...
let paths = [];
if (posts !== undefined) {
// .. add paths from posts to paths variable
return { paths, fallback: false };
}
// here the paths variable is empty, therefore the build fails
return { paths, fallback: false };
}
Is something like this even possible in Next.js?