I thought I'd write a quick solve here, because it took me a while to figure this out. I was tinkering around with my Next.js project, which was working fine, when suddenly this started happening..

Cue about 1.5 hours of root cause analysis, and trying to Google "on-demand-entries-client" and "Next.js 404" on Google, and no article was helping me. But then, a brain wave.. what's my middleware doing?
So I checked my middleware, and sure enough, this block was there..
if (!process.env.EDGE_CONFIG || !process.env.VERCEL_ENV) {
req.nextUrl.pathname = `/missing-edge-config`;
return NextResponse.rewrite(req.nextUrl);
}
This was the culprit. I had indeed forgotten to replace one of these variables in my local env. And that missing-edge-config page doesn't actually exist in my codebase! (It was a copy/paste from a Vercel blog post)
So, yeah - check your middleware for funkiness. Hope that saved you some time.

