Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!