You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Link to codesandbox is provided and it shows the issue as well.
Current vs. Expected behavior
The config object from middleware.ts is loaded correctly in case 1 (exporting during declaration) while it is not loaded correctly in case 2 (exporting after decleration):
import { NextRequest, NextResponse } from 'next/server';
// case 1 -> works as expected
export const middleware = (request: NextRequest) => {
console.log(request.nextUrl.pathname);
return NextResponse.next();
};
export const config = {
matcher: '/about',
};
// case 2 -> does not work as expected
const middleware = (request: NextRequest) => {
console.log(request.nextUrl.pathname);
return NextResponse.next();
};
const config = {
matcher: '/about',
};
export { middleware, config };
When the config is loaded only paths with /about should be printed in the console. If not loaded, all paths are printed in the console. Also no error is reported (I am not sure if an error should be reported).
Provide environment information
Sandbox is running on next.js version 15.0.0-canary-148. I encountered the same issue locally on 15.0.0-rc.0. Used app router in both instances.
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
Exporting the config object while declaring it solves the issue for me, but the difference should only be one of syntax and not functionality. The middleware function is unaffected by this issue, only the config object is affected.
This issue might be related but I'm not completely sure: #67169
In the case that it is feel free to remove this issue/combine both issues.
The text was updated successfully, but these errors were encountered:
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/nameless-hill-dt239f
To Reproduce
Link to codesandbox is provided and it shows the issue as well.
Current vs. Expected behavior
The config object from
middleware.ts
is loaded correctly in case 1 (exporting during declaration) while it is not loaded correctly in case 2 (exporting after decleration):When the config is loaded only paths with
/about
should be printed in the console. If not loaded, all paths are printed in the console. Also no error is reported (I am not sure if an error should be reported).Provide environment information
Sandbox is running on next.js version 15.0.0-canary-148. I encountered the same issue locally on 15.0.0-rc.0. Used app router in both instances.
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
Exporting the config object while declaring it solves the issue for me, but the difference should only be one of syntax and not functionality. The
middleware
function is unaffected by this issue, only theconfig
object is affected.This issue might be related but I'm not completely sure: #67169
In the case that it is feel free to remove this issue/combine both issues.
The text was updated successfully, but these errors were encountered: