Skip to content

Not working from Next.js middleware (edge runtime) when not using src folder #9631

@pladaria

Description

@pladaria

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

  1. npx create-next-app sentry-test. Create a new NextJS app with default values except the src directory (select No)
  • ✔ Would you like to use src/ directory? … No
  1. cd sentry-test. Enter to the directory
  2. npx @sentry/wizard@latest -i nextjs. Run the sentry wizard
  3. create a middleware.ts file (inside ./) that sends some traces to sentry, for example:
// ./middleware.ts
import {NextResponse} from 'next/server';
import * as Sentry from '@sentry/nextjs';

import type {NextRequest} from 'next/server';

export const middleware = (request: NextRequest): NextResponse => {
    Sentry.captureException(new Error('Sentry Example Middleware Error'));
    Sentry.captureMessage('Sentry Example Middleware Message', {
        level: 'info',
        extra: {
            method: request.method,
            path: request.nextUrl.pathname,
        },
    });
    console.log(request.method + ' ' + request.nextUrl.pathname);
    return NextResponse.next();
};
  1. yarn dev. Run the dev server and open http://localhost:3000

Expected Result

Receive issues from the middleware

We can verify that the middleware gets executed by looking at the console.logs from the terminal

Actual Result

Not receiving issues from middleware

Product Area

Unknown

Link

No response

DSN

No response

Version

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions