Make sure middleware.ts is placed in the root of the project, at the same level as next.config.js, not inside src/ or app/ folders.
Example:
/middleware.ts
/next.config.js
/package.json
If you’re using the App Router (app/ folder), make sure your middleware is in the root (not inside app)