Next-i18next: TypeError: Cannot read property 'allLanguages' of undefined

Created on 22 Jan 2019  路  7Comments  路  Source: isaachinman/next-i18next

Hi,

I tried the example in the documentation against the latest version (0.20.0) and got lots of warnings and errors:

warning  in ./pages/_app.js

"export 'appWithTranslation' was not found in '../i18n'

 warning  in ./pages/_app.js

"export 'i18n' was not found in '../i18n'

 warning  in ./components/NavBar.js

"export 'withNamespaces' was not found in '../i18n'

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'allLanguages' of undefined
    at _default (../app/store/node_modules/next-i18next/dist/middlewares/next-i18next-middleware.js:25:29)

Here is the i18n.js file:

import NextI18Next from 'next-i18next';

const options = {
  localePath: 'public/locales',
};
export default new NextI18Next(options);

Most helpful comment

Sorry it seems to be my own mistake. It's all good now.

Please to provide your own solution.

All 7 comments

Ok, the problem seems to be with the ES6 export in i18n.js. Changing it to module.exports fixed the warnings & the TypeError but not I got another one:

TypeError: Cannot read property 'bind' of undefined
    at WithMergedOptions.render (../app/store/node_modules/react-i18next/dist/commonjs/context.js:156:35)

This seems to happen only when I use withNamespaces() in a non-page component. Any ideas?

Please provide a reproducible repository. Thanks!

Sorry it seems to be my own mistake. It's all good now.

Sorry it seems to be my own mistake. It's all good now.

Please to provide your own solution.

The first part of this issue is related to #138, and a fix is incoming. However, I'm not sure about this part:

This seems to happen only when I use withNamespaces() in a non-page component. Any ideas?

I had the same error when I was using the basic react-i18next provider.

In my _app.js:

import {I18nextProvider} from 'react-i18next'; // Remove this
import i18next from '../utils/i18n'; // Remove this

class MyApp extends App {
  render() {
    return (
      <I18nextProvider i18n={i18next}>
         ...
        <Component {...pageProps} />
        ...
      </I18nextProvider>
    )
  }
}
Was this page helpful?
0 / 5 - 0 ratings