I was recently writing the middleware.ts
file in my Next.js project. And encountered the following situation:
// case 1
export const middleware = (...) => {...} // middleware works
export const config = {
matcher: '/about', // matcher works
};
// case 2
const middleware = (...) => {...} // middleware works
const config = {
matcher: '/about', // matcher does not work
};
export { middleware, config }
I was under the assumption that these ways of exporting functions and objects are equivalent. Is there some difference in practice (in terms of JavaScript modules)? Or is there a difference in the way Next.js is handling these for the middleware.ts
file in particular?
Other details: Next.js version 15.0.0-rc.0