I18nextProvider and testing recipe doesn't work with i18next v21.0.1 (typecheck error)
See original GitHub issue🐛 Bug Report
After upgrade of i18next from 20.6.1 to v21.0.1 the code related to react-i18next / testing without stubbing complains about a missing reportNamespaces
prop when instanciating the react-i18next provider.
Error output:
error TS2741: Property 'reportNamespaces' is missing in type
'import("/home/sebastien/github/nextjs-monorepo-example/node_modules/i18next/index").i18n'
but required in type
'import("/home/sebastien/github/nextjs-monorepo-example/node_modules/next-i18next/node_modules/i18next/index").i18n'.
To Reproduce
You can reproduce it on this branch: https://github.com/belgattitude/nextjs-monorepo-example/pull/458 or see the error message on the CI here: https://github.com/belgattitude/nextjs-monorepo-example/pull/458/checks?check_run_id=3672972037
Example code (was working on i18next < 21):
import i18n from 'i18next';
import type { FC } from 'react';
import { initReactI18next, I18nextProvider } from 'react-i18next';
/**
* Fully wrapped strategy for i18next, you can use stub/mocks as well
* @link {https://react.i18next.com/misc/testing}
*/
i18n.use(initReactI18next).init({
lng: 'en',
fallbackLng: 'en',
ns: ['common'],
defaultNS: 'common',
debug: false,
interpolation: {
escapeValue: false, // not needed for react!!
},
// Let empty so you can test on translation keys rather than translated strings
resources: { en: { common: {} } },
});
export const I18nextTestStubProvider: FC = ({ children }) => {
// THIS BREAKS AND COMPLAIN ABOUT MISSING reportNamespaces prop in i18n
return <I18nextProvider i18n={i18n}>{children}</I18nextProvider>;
};
Output log
error TS2741: Property 'reportNamespaces' is missing in type
'import("/home/sebastien/github/nextjs-monorepo-example/node_modules/i18next/index").i18n'
but required in type
'import("/home/sebastien/github/nextjs-monorepo-example/node_modules/next-i18next/node_modules/i18next/index").i18n'.
Expected behavior
Should not break.
Your Environment
- runtime version: node 14 lts
- i18next version: 21.0.1
- react-i18next version: i.e. 11.12.0
- os: Ubuntu
- typescript: 4.4.3
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Migration Guide - i18next documentation
This change streamlines the suffix with the one used in the Intl API. You may need to polyfill the Intl.PluralRules API, in case...
Read more >React i18next fails to load translation after in build
I don't know why react i18next display loading namespace fails on the debug console. I tried many suggestions without success.
Read more >I18n with Storybook - JS.ORG
This recipe shows you how. ➕ Expose i18next translations in Storybook Wrap stories with the i18next provider
Read more >Best React Localization - Internationalize with i18next ... - locize
Based on how long i18next already is available open source, there is no real i18n case that could not be solved with i18next....
Read more >react-i18next - npm
Source can be loaded via npm or downloaded from this repo. # npm package $ npm install react-i18next. If you don't use a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nice, thanks for letting me know @belgattitude!
@pedrodurek There might be an issue with yarn and peerDeps merged few hours ago.
I’ll upgrade to latest when released and I’ll let you know if it does actually fix the problem.