Middleware not working in Next.js

My middleware.ts file is in the root of the project, and I have this code in it:

import { NextRequest, NextResponse } from "next/server";

export function middleware(request: NextRequest) {
  return NextResponse.redirect(new URL("/new-page", request.url));
}

I followed the Next.js course, what am I doing wrong?

It doesn’t redirect me to /new-page.