Cloning produces error "Cannot read property 'toResolveHierarchy' of undefined"

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jamuhlcommented, Jun 10, 2017

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 instance auto.init()

after doing so cloning should be possible.

2reactions
jamuhlcommented, Jun 11, 2017

should be fixed in i18next@8.4.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloning produces error "Cannot read property 'toResolveHierarchy ...
I'm trying to create multiple instances of i18next with different lng : import i18next from 'i18next' const auto = i18next.createInstance ({ debug: !!...
Read more >
Cannot read property 'toResolveHierarchy' of undefined
Maybe it is caused by a bad import of i18next or that it hasn't been inited, like "import i18n from 'i18next'". Run the...
Read more >
how to setup react-i18n with hooks, getting TypeError - Reddit
While trying to setup react-i18n with hooks, comes this error TypeError: Cannot read property '0' of undefined. Here is i18n.js
Read more >
i18next | Yarn - Package Manager
... even if no lng set or detected at least load the fallback languages ... toResolveHierarchy does not add undefined as code if...
Read more >
Golf putting model - QHELP
p("Just press the 'Set direction' button and see what happens. ... multiple = TRUE, selected = files[1]) }) # Load data ## reads...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found