I18next: initReactI18next not recognized as a module when upgrading from 19.3.4 to 19.4.1

Created on 11 Apr 2020  路  4Comments  路  Source: i18next/i18next

Since upgrading i18next to version 19.4.1, my Jest tests are failing (version of react-i18next: 11.3.4, using CRA 3.4.1):

  You are passing a wrong module! Please check the object you are passing to i18next.use()

      12 | import { initReactI18next } from 'react-i18next';
      13 | 
    > 14 | i18n.use(initReactI18next)

The code starts as follows:

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

i18n.use(initReactI18next).init({
  fallbackLng: 'en',
  ns: ['translations'],
  defaultNS: 'translations',
});

Most helpful comment

Thank you for the quick turnaround. Found the root cause: a mock was added for "react-i18next" in common test utils. The interesting part is that until 19.4.1, I did not get above warning.

So this is a good thing it errors now. Apologies.

All 4 comments

the check is: https://github.com/i18next/i18next/blob/master/src/i18next.js#L200 with initReactI18next = https://github.com/i18next/react-i18next/blob/master/src/context.js#L59

So the question is - what is initReactI18next in your case?

Thank you for the quick turnaround. Found the root cause: a mock was added for "react-i18next" in common test utils. The interesting part is that until 19.4.1, I did not get above warning.

So this is a good thing it errors now. Apologies.

Sorry but can you please explain a bit more I am also facing the same issue. What exactly you mean by common test utils?

Was this page helpful?
0 / 5 - 0 ratings