aralroca / next-translate

Next.js plugin + i18n API for Next.js 🌍 - Load page translations and use them in an easy way!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot read properties of undefined (reading 'loadLocaleFrom')

brunoscopelliti opened this issue · comments

What version of this package are you using?

"next": "13.5.4",
"next-translate": "^2.6.0",
"next-translate-plugin": "^2.6.0",

What operating system, Node.js, and npm version?

macOS Ventura
node: 20.5.0
npm: 9.8.0

Error

TypeError: Cannot read properties of undefined (reading 'loadLocaleFrom')

I get the above error when using getT in an API route.
The weird thing is that the error happens only the first time the api is executed.

const t = await getT(request.headers.get("lang") || "en", ["errors"]);

Steps to reproduce

  1. Download the archive, repro.zip.
  2. Install dependencies and run npm run dev
  3. Visits localhost:3000/api/test

Notice the error in console: TypeError: Cannot read properties of undefined (reading 'loadLocaleFrom')

  1. Reload the page

You should see something like:

{
    "code": "error_1",
    "debugLang": "en",
    "label": "errors:error_1",
    "status": "KO"
}

The error is gone, but for some reason the label is still not correctly read.

  1. In a different browser tab visits localhost:3000/demo

This page should be rendered correctly (it also renders a label from the JSON file).

  1. Go back to the tab open on the API route (localhost:3000/api/test) and reload it again.

You should finally see something like:

{
    "code": "error_1",
    "debugLang": "en",
    "label": "EN: Errore 1",
    "status": "KO"
}

Same problem as here.
Sorry for the duplicate.