nextjs - 💡(How to fix) Fix App Router API routes hang on Vercel in pnpm monorepo with Root Directory — Next.js 16.1.6 [4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#91432Fetched 2026-04-08 02:02:00
View on GitHub
Comments
4
Participants
3
Timeline
9
Reactions
0
Author
Timeline (top)
commented ×4labeled ×2closed ×1cross-referenced ×1

Code Example

export async function GET() {
  return new Response(JSON.stringify({ pong: true, ts: Date.now() }), {
    status: 200,
    headers: { "Content-Type": "application/json" },
  });
}

---

Route (app)
┌ ○ /
├ ○ /_not-found
└ ƒ /api/ping
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/JMill/nextjs16-api-hang-repro

To Reproduce

  1. Import the repo to Vercel (or fork and connect)
  2. Set Root Directory to apps/web in Vercel project settings
  3. Deploy
  4. Visit {deployment-url}/ → works (200)
  5. Visit {deployment-url}/api/pinghangs indefinitely, eventually 504

Current vs. Expected behavior

Current: All App Router API routes hang with - status in Vercel runtime logs, eventually returning 504 Gateway Timeout. This includes a zero-import route that just returns new Response(JSON.stringify({pong:true})).

Expected: API routes should return responses, same as they do locally with next start.

Provide environment information

  • Next.js: 16.1.6
  • React: 19.x
  • Node.js: tested both 20.x and 24.x
  • pnpm: 10.29.3
  • Turbopack (default) — also tested with --webpack
  • Vercel Pro plan
  • Monorepo: pnpm workspaces + Turborepo
  • Vercel Root Directory: apps/web

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

App Router, Deploying, Turbopack

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

Production (Vercel)

Additional context

Pages (SSR/SSG) work perfectly on the same deployment — only API route handlers hang.

The reproduction repo is a minimal pnpm monorepo with:

  • apps/web — Next.js 16 app with one page and one API route
  • packages/shared — trivial shared package
  • Turborepo for build orchestration

The API route (/api/ping) has zero imports:

export async function GET() {
  return new Response(JSON.stringify({ pong: true, ts: Date.now() }), {
    status: 200,
    headers: { "Content-Type": "application/json" },
  });
}

Locally with next start, the route works perfectly. On Vercel with Root Directory = apps/web, it hangs.

Build output correctly shows the route as a dynamic function:

Route (app)
┌ ○ /
├ ○ /_not-found
└ ƒ /api/ping

Exhaustive testing done on the original project (14 diagnostic deployments):

  • Deleted proxy.ts entirely — still hangs
  • Node.js 24 → 20 — still hangs
  • Turbopack → webpack — still hangs
  • Disabled Deployment Protection — still hangs
  • Approved pnpm native build scripts — still hangs

This suggests the issue is in how Vercel's deployment adapter creates/invokes serverless functions when Root Directory is set to a monorepo subdirectory.

extent analysis

TL;DR

The most likely fix involves adjusting the Vercel configuration to properly handle serverless functions within a monorepo setup, potentially by modifying the vercel.json configuration or adjusting the build settings.

Guidance

  1. Verify Vercel Configuration: Review the vercel.json file to ensure it is correctly configured for a monorepo setup with a Root Directory set to a subdirectory (apps/web).
  2. Check Serverless Function Handling: Investigate how Vercel's deployment adapter handles serverless functions when the Root Directory is set to a monorepo subdirectory, as this might be the root cause of the issue.
  3. Adjust Build Settings: Consider adjusting the build settings in turbo.json or next.config.js to ensure that the build output correctly reflects the dynamic nature of the API route.
  4. Test with Minimal Configuration: Try deploying a minimal Next.js application with a single API route to Vercel, using the same monorepo setup, to isolate if the issue is specific to the current project configuration or a more general problem with Vercel and monorepos.

Example

No specific code example can be provided without further details on the Vercel configuration and build settings. However, ensuring that the vercel.json contains the correct settings for the monorepo and that the next.config.js is properly configured for serverless functions could look something like this:

// vercel.json
{
  "version": 2,
  "routes": [
    {"src": "/api/(.*)", "dest": "apps/web/api/$1"}
  ]
}

Notes

The issue seems to be related to how Vercel handles serverless functions within a monorepo setup. The provided reproduction repository and extensive testing suggest that the problem is not with the Next.js version, Node.js version, or the build tool (Turbopack vs. Webpack), but rather with how Vercel deploys and invokes serverless functions from a subdirectory.

Recommendation

Apply a workaround by adjusting the Vercel configuration and build settings to properly handle serverless functions within the monorepo setup, as the root cause seems to be related to this specific deployment scenario.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix App Router API routes hang on Vercel in pnpm monorepo with Root Directory — Next.js 16.1.6 [4 comments, 3 participants]