Error: The Middleware "/middleware" must export a middleware or a default function
Unanswered
Goldstripe sardinella posted this in #help-forum
Goldstripe sardinellaOP
### Summary
I have a problem with middleware in the last version of next.js, I get this error every time.
at <unknown> (edge-wrapper.js:2:6)
1 | self._ENTRIES ||= {};
3 | modProm.catch(() => {});
4 | self._ENTRIES["middleware_middleware"] = new Proxy(modProm, {
5 | get(modProm, name) {
GET / 404 in 4ms
import createIntlMiddleware from 'next-intl/middleware'
import { NextRequest } from 'next/server'
import { locales } from '@i18n/routing'
export default async function middleware(request: NextRequest) {
const headerLocale = request.headers.get('x-test-locale')
const defaultLocale = (headerLocale ?? locales[0]) as (typeof locales)[number]
const handleI18nRouting = createIntlMiddleware({
locales: locales,
defaultLocale: defaultLocale
})
const response = handleI18nRouting(request)
response.headers.set('x-test-locale', defaultLocale)
return response
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)']
}
```
I have a problem with middleware in the last version of next.js, I get this error every time.
Error: The Middleware "/middleware" must export a `middleware` or a `default` function
and in the console, this one :
```
⨯ Error: The Middleware "/middleware" must export a
middlewareor a
default` functionat <unknown> (edge-wrapper.js:2:6)
1 | self._ENTRIES ||= {};
2 | const modProm = import('MODULE');| ^
3 | modProm.catch(() => {});
4 | self._ENTRIES["middleware_middleware"] = new Proxy(modProm, {
5 | get(modProm, name) {
GET / 404 in 4ms
### Additional information
jsimport createIntlMiddleware from 'next-intl/middleware'
import { NextRequest } from 'next/server'
import { locales } from '@i18n/routing'
export default async function middleware(request: NextRequest) {
const headerLocale = request.headers.get('x-test-locale')
const defaultLocale = (headerLocale ?? locales[0]) as (typeof locales)[number]
const handleI18nRouting = createIntlMiddleware({
locales: locales,
defaultLocale: defaultLocale
})
const response = handleI18nRouting(request)
response.headers.set('x-test-locale', defaultLocale)
return response
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)']
}
```