Cloning produces error "Cannot read property 'toResolveHierarchy' of undefined"
See original GitHub issueI’m trying to create multiple instances of i18next with different lng:
import i18next from 'i18next'
const auto = i18next.createInstance ({
debug: !!FocusCraft.config.debug,
load: 'languageOnly',
lng: navigator.language || navigator.userLanguage,
fallbackLng: 'en',
resources: {
en: {
hello: 'Hello World!',
},
ru: {
hello: 'Привет мир!',
},
},
})
const locales = {
en: auto.cloneInstance ({ lng: 'en' }),
ru: auto.cloneInstance ({ lng: 'ru' }),
}
…But once it gets to cloneInstance(), i18next dies with an error:
i18next.js:273 Uncaught TypeError: Cannot read property ‘toResolveHierarchy’ of undefined at setLng (i18next.js:273) at I18n.changeLanguage (i18next.js:290) at load (i18next.js:159) at I18n.init (i18next.js:169) at I18n.cloneInstance (i18next.js:392) at Object.defineProperty.value (i18n.js:19) at webpack_require (bootstrap 06f5bf9…:19) at Object.defineProperty.value (App.jsx:9) at webpack_require (bootstrap 06f5bf9…:19) at Object.defineProperty.value (AppContainer.jsx:5) at webpack_require (bootstrap 06f5bf9…:19) at Object.<anonymous> (main.jsx:11) at webpack_require (bootstrap 06f5bf9…:19) at Object.<anonymous> (emitter.js:2) at webpack_require (bootstrap 06f5bf9…:19) at bootstrap 06f5bf9…:65
In this case, I’d really like to keep several instances. I could just create them individually, but clones would be better, as they supposedly share resources. Am I using clones in a wrong way?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Related StackOverflow Question
Calling
i18next.createInstance(opts)will not initialize it.a) pass a callback
i18next.createInstance(opts, cb)so init will be called on creating b) call init on the instanceauto.init()after doing so cloning should be possible.
should be fixed in i18next@8.4.2