AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Rewrites To API Routes Return 404 On Vercel When I18n Is Enabled

When using i18n with custom rewrites that target API routes, deployed applications on Vercel return 404 for those rewritten paths, even though they work in local development. This appears to be caused by a routing priority issue between i18n locale handling and API route rewrites.

highConfidence 70%Next.jsTurbopackServer ActionsHydrationAffected V10.0.9Fixed V10.2.0

Origin Analysis

Next.js generates Vercel routing rules that give i18n locale detection higher priority than custom rewrites, particularly when the rewrite source includes a locale prefix (e.g., '/en/robots.txt'). As a result, requests are incorrectly matched to page routes instead of the intended API routes, leading to 404 errors on the Vercel edge network.
1. Create a Next.js app with the provided i18n and rewrites configuration. 2. Deploy the app to Vercel. 3. Access '/en/robots.txt', '/en/sitemap.xml', or any '/api/missing-route' – all return Vercel's 404 page, while the same requests work in development.

Fixing Code Block

Edge Case Audit

This fix requires upgrading Next.js to at least 10.2.0, which may introduce other breaking changes. The `beforeFiles` rewrites have the highest priority and can override static files and public assets if not carefully scoped. Ensure that `/robots.txt` and `/sitemap.xml` are not intended to be served from the `public` directory, as the rewrite will intercept them. In case of issues, rollback by reverting the `next.config.js` to the original rewrites array and downgrading Next.js to the previous version. Thoroughly test all locale-specific routes after applying.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state