Middleware not called when using custom pageExtensions
Β #38233
Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
Binaries:
Node: 16.15.1
npm: 8.11.0
Yarn: 1.22.19
pnpm: 7.3.0
Relevant packages:
next: 12.2.1-canary.1
eslint-config-next: 12.2.0
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
In 12.2, the middleware.ts
file should be placed in the root directory next to the pages
folder. However, when using the pageExtensions
option in the next.config.js
it is never being called.
Removing the setting allows you to call the middleware.
Renaming the middleware.ts
file to middleware.api.ts
in this case will make it work too. However, I don't believe the middleware is a "page" as it lives outside the pages folder.
Pre-12.2, it was called _middleware.ts
and it did ignore the set page extensions.
Expected Behavior
The middleware should be called even when having set custom page extensions by ignoring those as it lives outside the /pages
folder.
Or
The documentation should mention it is a "page" file and requires to have one of the set page extensions.
Link to reproduction
https://github.com/bjarn/next-middleware-bug
To Reproduce
Breaks when adding pageExtensions: ["api.ts", "page.tsx"],
to the next.config.js. Removing fixes the issue.