vercel / vercel/next.js

next 16.2.1 trpc error

Open
#92,114 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Connection
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/chagas42/next-16.2.1-trpc-error

To Reproduce
  1. Clone the minimal reproduction: https://github.com/chagas42/next-16.2.1-trpc-error

  2. Create a free Clerk app at https://clerk.com and copy the API keys

  3. In the Vercel dashboard, import the cloned repo and add the environment variables:

    • NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
    • CLERK_SECRET_KEY=
  4. Deploy to Vercel and open the preview URL

  5. Open DevTools → Network tab → filter by Fetch/XHR

  6. Observe that all requests to /api/trpc/* return 404 Not Found

The API route at pages/api/trpc/[trpc].ts is never reached. Vercel logs show:

Middleware:  200        ← proxy.ts ran, returned NextResponse.next()
Cache:       404 Not Found
Status:      HIT
Key:         /pt-BR/404

───────────────────────────────

Current vs. Expected behavior

Expected: GET /api/trpc/hello reaches the API route handler and returns a valid response.

Observed: Every request to /api/trpc/* returns 404 Not Found on all new Vercel deployments.

Vercel logs for the failing request show:

Middleware:  200          ← middleware ran successfully, returned NextResponse.next()
Cache:       404 Not Found
Status:      HIT
Key:         /pt-BR/404   ← static i18n 404 page served instead of the API handler

The static pre-rendered 404 page for the default locale (pt-BR) is being served from Vercel's Full Route Cache for all API route paths. The route handler is never invoked.

Vercel also logs the internal path as /pt-BR/api/trpc/[route] — the i18n locale prefix is being applied to the API route, even though pages/api/ routes should be exempt from i18n locale prefixing.

Additional notes:

  • Works correctly with next build && next start locally
  • Works correctly via Vercel Instant Rollback to a build from the previous day
  • Fails on every new Vercel build regardless of code changes
  • Removing the /(api|trpc)(.*) matcher from proxy.ts is a workaround but breaks other middleware behavior
Provide environment information
Operating System:
    Platform: darwin
    Arch: arm64
    Version: Darwin Kernel Version 25.2.0
    Available memory (MB): 16384
    Available CPU cores: 8
  Binaries:
    Node: 24.10.0
    npm: 11.6.1
    Yarn: 1.22.22
    pnpm: 10.19.0
  Relevant Packages:
    next: 16.2.1
    eslint-config-next: N/A
    react: 19.2.4
    react-dom: 19.2.4
    typescript: 5.9.3
  Next.js Config:
    output: N/A
Which area(s) are affected? (Select all that apply)

Connection

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

Only reproducible on Vercel (preview and production deployments). Works correctly with next build && next start locally.

The issue appears to be related to the combination of:

  • i18n with a non-English defaultLocale (pt-BR)
  • Middleware using proxy.ts filename (Next.js 16 feature) with a matcher that includes /(api|trpc)(.*)
  • Clerk middleware + @vercel/functions geolocation

Vercel logs show the middleware runs successfully (200) but the request is served from the Full Route Cache with key /pt-BR/404 — the static i18n 404 page — instead of reaching the API route handler. The internal path
logged by Vercel shows /pt-BR/api/trpc/[route], suggesting the i18n locale prefix is incorrectly being applied to API routes.

An Instant Rollback to a deployment built the previous day restores correct behavior. Every new build fails.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproduction and inspect proxy.ts alongside pages/api/trpc/[trpc].ts. Deploy it to Vercel, compare the failing request and logs with next build && next start locally, and trace the /pt-BR/api/trpc/[route] and /pt-BR/404 paths. Done means /api/trpc/hello reaches the handler on new deployments without removing the existing middleware behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react, typescript
Domain
api, backend, cloud, internationalization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.