Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

forEach loop breaking when no namespaces are set on init #1709

Closed
DannyvanHolten opened this issue Dec 16, 2021 · 6 comments
Closed

forEach loop breaking when no namespaces are set on init #1709

DannyvanHolten opened this issue Dec 16, 2021 · 6 comments

Comments

@DannyvanHolten
Copy link

@DannyvanHolten DannyvanHolten commented Dec 16, 2021

馃悰 Bug Report

forEach loop breaking when no namespaces are set on init

To Reproduce

A codesandbox example or similar
or at least steps to reproduce the behavior:

import i18n from "i18next";
import Backend from "i18next-http-backend";
import { initReactI18next } from "react-i18next";

i18n
  .use(Backend)
  .use(initReactI18next)
  .init({
     ns: [],
   })

Console error:

react_devtools_backend.js:4045 TypeError: Cannot read properties of undefined (reading 'forEach')
    at i18next.js:880
    at Array.forEach (<anonymous>)
    at Translator.resolve (i18next.js:865)
    at Translator.translate (i18next.js:744)
    at I18n.t (i18next.js:2544)
    .... etc.

Expected behavior

I'm trying to upgrade from i18next 20 to i18next 21. In our app, we do not load any namespaces by default and have no default translations file (all is being imported through the use of namespaces through component hooks).

Because my array of ns is empty it breaks initialization. And it requires me to specify a namespace that is loaded by default . Which I don't want to.

I believe this is because of how the new defaultNs is being loaded. It seems to not check if the ns property actually contains values or is an empty array.

Your Environment

  • runtime version: node 14
  • i18next version: i18next 21.1.6 (upgrading from 20.3.1)
  • os: Mac
  • any other relevant information: Running together with i18next-backend and i18next-react
@adrai
Copy link
Member

@adrai adrai commented Dec 16, 2021

Can you please provide a reproducible example? I'm not able to reproduce it.

@adrai
Copy link
Member

@adrai adrai commented Dec 16, 2021

I found it...
Can you try with v21.6.1?

@DannyvanHolten
Copy link
Author

@DannyvanHolten DannyvanHolten commented Dec 16, 2021

It is indeed fixed. WOW, this was so fast. Thanx for that!

@adrai
Copy link
Member

@adrai adrai commented Dec 16, 2021

If you like this module don鈥檛 forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.

There are many ways to help this project 馃檹

@DannyvanHolten
Copy link
Author

@DannyvanHolten DannyvanHolten commented Dec 16, 2021

P.S: Did you leave in a rogue console.log?

My console is printing my namespaces.

@adrai
Copy link
Member

@adrai adrai commented Dec 16, 2021

yep, sorry... v21.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants