Closed molily closed 2 months ago
that initReactI18Next part is important to be like this: import { initReactI18next } from 'react-i18next/initReactI18next'
else client only code will be loaded....
Here is the export in the package.json https://github.com/i18next/react-i18next/blob/master/package.json#L42
so tldr;
keep import { initReactI18next } from 'react-i18next/initReactI18next'
Thanks! I got a "Module not found" error in my real app, but I could pin this down to the custom Webpack setup and I was able to fix the error.
Hello, first of all, thank you for this project!
🐛 Bug Report
Importing react-i18next in a Next.js server component causes a
createContext is not a function
error.I have created a fresh Next.js 14 project with
create-next-app
featuring theapp
dir: https://github.com/molily/next-js-rsc-react-i18nextI've been following this tutorial to integrate translations with i18next: https://locize.com/blog/next-app-dir-i18n/
While this tutorial implements a many things, I tried to implement the minimal translation logic for React Server Components first: https://github.com/molily/next-js-rsc-react-i18next/blob/main/src/app/i18n/useTranslation.ts
The page: https://github.com/molily/next-js-rsc-react-i18next/blob/main/src/app/page.tsx
Note that this page does not have
'use client'
, so it should be handled as a server component. (Which is fine for now – I'd like to get RSCs working first before adding the client-side logic, like the tutorial suggests.)Opening this page gives me the error:
There's no
createContext
in RSCs, so that error seems logical – but shouldn't this approach be catered to RSC specifically? Am I doing something wrong?Note: Compared to the tutorial, I've changed
to
because Next complained that there is no module at 'react-i18next/initReactI18next'.
Reproducing
npm install
,npm run dev
Your Environment
Thanks a lot for looking into this, much appreciated.