-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Description
Link to the code that reproduces this issue
https://github.com/createdbymax/nextjs-turbopack-post-bug
To Reproduce
- Create a Next.js 16.1.4 app with App Router
- Create an API route at
src/app/api/test/route.ts:
import { NextResponse } from "next/server";
export async function POST(request: Request) {
const body = await request.json();
console.log('API route hit:', body);
return NextResponse.json({ success: true });
}
Create a client component with a button that calls the API:
"use client";
export function TestComponent() {
const handleClick = async () => {
console.log('Fetching...');
const response = await fetch('/api/test', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ test: 'data' }),
});
console.log('Response:', response.status);
};
return Test API;
}
Run next dev (Turbopack enabled by default in Next.js 16)
Click the button
Observe: Browser logs "Fetching..." but server terminal never logs the request
### Current vs. Expected behavior
Expected: POST request reaches the API route handler and server logs show:
POST /api/test 200 in XXms
Actual:
Browser console shows fetch is called with correct URL and payload
Request appears in browser Network tab as "pending" indefinitely
Server terminal shows NO log of the incoming request
Request never completes or times out
Browser Console:
Fetching...
# Request hangs here forever
Server Terminal:
▲ Next.js 16.1.4 (Turbopack)
- Local: http://localhost:3000
✓ Ready in 548ms
GET /some-page 200 in 3.0s
# POST /api/test never appears
### Provide environment information
```bash
Operating System:
Platform: darwin
Arch: arm64
Version: macOS
Node: 24.8.0
pnpm: (run pnpm -v to get version)
Relevant Packages:
next: 16.1.4
react: 19.2.3
react-dom: 19.2.3
typescript: 5.x
Which area(s) are affected? (Select all that apply)
Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
GET requests to API routes work fine
POST requests to the same route work intermittently when the server first starts, before Turbopack fully initializes
Middleware is configured to exclude /api routes:
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|login).*)"],
};
Workarounds attempted:
- TURBOPACK=0 next dev - Still uses Turbopack in Next.js 16
- Using absolute URL ${window.location.origin}/api/test - Still doesn't reach server
- rm -rf .next - No effect
- Downgrading to Next.js 15.1.3 - Resolves the issue
This appears to be a critical routing bug in Turbopack that prevents POST requests from client components from reaching API route handlers.