#middleware

1 messages · Page 1 of 1 (latest)

upper valve
#

/middleware contains invalid middleware config: Expected string, received object at "matcher", or Expected array, received object at "matcher"

karmic pineBOT
#

Hi @upper valve. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, it appears you're encountering an issue with the configuration of your Next.js middleware. This error typically occurs when the matcher property in the middleware configuration is not formatted correctly. Let's address this issue:

The error message suggests that the matcher property is expecting either a string or an array, but it's receiving an object. This is likely due to a mismatch between the configuration syntax you're using and what Next.js expects.

According to the Next.js documentation, the matcher can be defined in several ways:

  1. As a single string:
export const config = {
  matcher: '/about/:path*',
}
  1. As an array of strings:
export const config = {
  matcher: ['/about/:path*', '/dashboard/:path*'],
}
  1. As an array of objects with more complex configurations:
export const config = {
  matcher: [
    {
      source: '/((?!api|_next/static|_next/image|favicon.ico).*)',
      missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
      ],
    },
  ],
}

However, it's worth noting that there seems to be an ongoing issue with parsing more complex matcher configurations when using Turbopack (Next.js' new bundler) as reported in this GitHub issue (https://github.com/vercel/next.js/issues/64747).

To resolve your issue, you could try simplifying your matcher configuration to use string patterns instead of objects. For example:

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
}

If you need more complex matching behavior, you might need to implement it within the middleware function itself rather than in the matcher configuration.

#

If the issue persists, it might be related to the version of Next.js you're using or potential bugs in the current implementation. In that case, you may want to check for updates or report the issue on the Next.js GitHub repository (https://github.com/vercel/next.js/issues).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: