I am having the same error:
[Error: Failed to collect configuration for /_not-found]
Later, I found out that my .env file was missing a variable. Adding that environment variable solved this build error.
Also, try deleting the ".next" folder if you are self-hosting your project.