It's very much the same discussion as #8676, albeit with a new insight. I've also posted this in GitHub discussions at https://github.com/vercel/vercel/discussions/13283
My codebase has an extensive Content Security Policy (CSP) setup. I.e. many HTTP headers. Vercel is therefore giving the error 'Builder returned invalid routes: should NOT be longer than 4096 characters' during Vercel builds.
Please consider this discussion as a feature request and opportunity to help others.
- I would expect this error to happen on localhost in a
next buildsince the Vercel-Next.js relation is strong. - My solution was to relax the CSP config. Instead of listing hardcoded domains, I've basically reverted to a 'allow most' setup. I think Vercel's technical setup should NOT reduce security.
The reason for the many CPS entries is the Google Tag Manager requirement to list all Google TLDs. See https://developers.google.com/tag-platform/security/guides/csp#google_analytics_4_google_analytics