Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
7.64.0
Framework Version
7.64.0
Link to Sentry event
No response
SDK Setup
Sentry.init({
dsn: "DSN",
tracesSampleRate: 1,
debug: false,
});
Steps to Reproduce
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.
npx create-next-app --example reproduction-template reproduction-app
cd reproduction-app
npx @sentry/wizard -i nextjs
mkdir src
mv app src/
touch src/middleware.ts
- Middleware contents:
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.
Metadata
Metadata
Assignees
Type
Projects
Status
No status