Error occured prerendering page /_not-found

I’m getting the “error occurred prerendering page /_not-found error”:

Error occurred prerendering page "/_not-found". Read more: [Prerender Error with Next.js | Next.js](https://nextjs.org/docs/messages/prerender-error)
TypeError: Cannot read properties of undefined (reading 'toString')
at a (/vercel/path0/.next/server/chunks/947.js:4:48057)
at i (/vercel/path0/.next/server/chunks/947.js:4:48172)
at /vercel/path0/.next/server/chunks/947.js:4:48414
at Array.map (<anonymous>)
at u (/vercel/path0/.next/server/chunks/947.js:4:48407)
at S (/vercel/path0/.next/server/chunks/947.js:2:17695)
Export encountered an error on /_not-found/page: /_not-found, exiting the build.
⨯ Next.js build worker exited with code: 1 and signal: null
ELIFECYCLE Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1

I saw on forums here that changing the build root directory might help, but all of my files are in the same root directory.
Example:
/project
/app
/hook
/components
/lib
/public
package.json
tailwind.config.js
etc.

That way I can’t set the root directory as it’s already set to the main one, so that won’t help.