next.js: Middleware does not function in Next.js 13 while using Turbopack

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Wed Mar 2 00:30:59 UTC 2022
Binaries:
  Node: 19.0.0
  npm: 8.19.2
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.3-canary.4
  eslint-config-next: 13.0.3
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Using next dev --turbo causes middleware not to execute.

Expected Behavior

Using next dev --turbo should not affect middleware execution.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/scissorhands26/nextjs-13-middleware-turbopack-bug

To Reproduce

Use middleware in conjunction with the pages or app directory, and add the --turbo flag to "dev": "next dev --turbo".

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 41
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Any update here? I am still seeing this.

Any update?

A year has passed and you still can’t use turbo with a middleware…omg

Has there been any progress on this? We are also facing this issue inside a turborepo project on 14.0.0 . Removing the src folder does make the middleware run, but it is not an ideal solution. Is there a flag we should use like --root in this case?

EDIT: I made a new reproduction repo for the latest version: https://github.com/daniel-koudouna/next14-middleware

Sorry for the long wait, a fix is in #58218

I encountered the same issue when using next dev --turbo. If my code is located in the src directory, the middleware does not run.

My solution was to move the app directory and middleware.js to the root directory. This way, the middleware can run.

I’m experiencing this issue as well. I was looking to build a library that integrates well with Turbopack, but this is the last blocker I’m facing at the moment.

having the same issue in a turborepo environment

+1 seeing the same issue, middleware.ts in /src folder with /app directory and it doesn’t get picked up while using --turbo

Any update on this yet? We are still facing this issue too. We’d like to maintain the existing folder structure.

Also observed in this closed issue: https://github.com/vercel/turbo/issues/2905