Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
Next-JS middleware ( NextRequest.nextUrl.locale ) return empty string in deployed

I have a bug in next-js middleware

in middleware function is return a NextRequest pram in nextjs docs say:

The NextRequest object is an extension of the native Request interface, with the     
following added methods and properties:

- cookies - A Map with cookies from the Request. See Using cookies in Middleware
- nextUrl: Includes an extended, parsed, URL object that gives you access to Next.js 
- specific properties such as pathname, basePath, trailingSlash and i18n. Includes the 
- following properties:
- basePath (string)
- buildId (string || undefined)
- defaultLocale (string || undefined)
- domainLocale
  - defaultLocale: (string)
  - domain: (string)
  - http: (boolean || undefined)
  - locales: (string[] || undefined)
- locale (string || undefined)

thats mean I can access current locale from NextRequest.nextUrl.locale. good, this is working in localhost and already I get a locale.

but after deploy project in netlify and print NextRequest.nextUrl.locale in console thus

console.log({locale: NextRequest.nextUrl.locale});

is returned me

{ locale: "" }

meaning NextRequest.nextUrl.locale = "" & empty String

why this bug ??

thats my code

const middleware = async (req) => {
  if (
    req.nextUrl.pathname.startsWith("/_next") ||
    req.nextUrl.pathname.includes("/api/") ||
    PUBLIC_FILE.test(req.nextUrl.pathname)
  ) {
    return;
  }
  
  
  console.log({locale: req.nextUrl.locale});

  return;
};

export { middleware };

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Did you remember to add Internationalized Routing to your next.config.js

https://nextjs.org/docs/advanced-features/i18n-routing

My experience is that locale is only populated when i18n is used.

almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda