You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[nextjs] Placing middleware.ts in src directory causes middleware to be ignored #8845
Basically, middleware gets bypassed/ignored when the middleware.(ts|js) file is placed in the src folder, something that is supported according to Next.js documentation.
export function middleware(request) {
throw new Error("This never runs");
}
mkdir -p src/app/api/test
touch src/app/api/test/route.ts
src/app/api/test/route.ts contents:
import { NextResponse } from "next/server";
export function GET() {
return NextResponse.json(
{
success: "middleware not called",
},
{ status: 200 }
);
}
yarn build && yarn start
curl http://localhost:3000/api/test
Expected Result
The curl request never reaches the src/api/test/route.ts route due to middleware throwing an error.
According to Next.js's documentation on middleware conventions the middleware.ts file should be able to be placed in both the root and in the src directory.
Actual Result
The curl request reaches the src/api/test/route.ts route.
Activity
lforst commentedon Aug 23, 2023
sourcemaps around middleware (especially in Vercel edge runtime) are still very funky. We need to fix this.
lforst commentedon Nov 7, 2023
Fixed with #9454
(please not that sourcemaps for edge on Vercel are still broken - this needs support from Vercel's side)
Lms24 commentedon Nov 8, 2023
This was released in version 7.78.0 of
@sentry/nextjs