404 error handler fails on Next.js 14 site

I’m hosting a site built with Next.js on Netlify, and using the standard deploy rather than a static export, and the default settings for deploying Next.js. I originally built it with Next 13, but have updated it recently to Next 14, and it has used the app router since the beginning. It’s at https://highperformancelaravel.com/.

Last weekend I noticed an issue raised by Ahrefs on the site. It was checking for the sitemap at https://highperformancelaravel.com/sitemap_index.xml. While this isn’t where the sitemap normally is (I’m using next-sitemap, which places it at /sitemap.xml), it had been returning a proper 404 response. Now it throws a 502 error with the following text:

This function has crashed
An unhandled error in the function code triggered the following message:

Runtime.UnhandledPromiseRejection - Error: Error handling request. See function logs for details.

Stack trace
Runtime.UnhandledPromiseRejection: Error: Error handling request. See function logs for details.
    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)
    at process.emit (node:events:529:35)
    at emit (node:internal/process/promises:149:20)
    at processPromiseRejections (node:internal/process/promises:283:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)

The function log returns the following:

Nov 5, 02:30:36 PM: a17ef05a ERROR  Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Error handling request. See function logs for details.","reason":{"errorType":"Error","errorMessage":"Error handling request. See function logs for details.","stack":["Error: Error handling request. See function logs for details.","    at Server.<anonymous> (/var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js:88:23)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Error handling request. See function logs for details.","    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)","    at process.emit (node:events:529:35)","    at emit (node:internal/process/promises:149:20)","    at processPromiseRejections (node:internal/process/promises:283:27)","    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}Nov 5, 02:30:36 PM: Unknown application error occurred
Runtime.UnknownNov 5, 02:30:36 PM: a17ef05a Duration: 358.34 ms	Memory Usage: 35 MB	Nov 5, 02:30:36 PM: INIT_START Runtime Version: nodejs:18.v15	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:8ed78fdc4678dbafe30d2afe48bcfb27097048de7858a6fbbba5d19fdc3419db

The same happens for any other 404 errors, despite there being a root app/not-found.tsx file that works as expected when running locally

These errors are rather opaque and I can’t see anything helpful. Can anyone suggest how I might resolve this please?

Given that Next 13 itself is having several issues on Netlify, I won’t recommend using Next 14 right now.

The issue also occurs in Next 13 - downgrading didn’t resolve the issue.

Yes, but next 13 is also having issues on our platform. Can you try downgrading one more time please?

Unfortunately that isn’t practical as it’s using the app router.

Okay, but there’s nothing we can do to solve it right now. You can try waiting till we fix the issues.

Hey, you can now opt-in to our new Next.js runtime (v5) which should resolve this, when coupled with Next.js 13.5+.