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
- Download the archive, repro.zip.
- Install dependencies and run
npm run dev
- Visits localhost:3000/api/test
Notice the error in console: TypeError: Cannot read properties of undefined (reading 'loadLocaleFrom')
- 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.
- In a different browser tab visits localhost:3000/demo
This page should be rendered correctly (it also renders a label from the JSON file).
- 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.