-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: i18n.changeLanguage is not a function #107
Comments
As for the second error, when I debug the client side, I get this warning after a navigation:
|
@janhesters maybe you forgot to create the JSON files in the public folder... or maybe you're using a different key then I have the same error above with |
@janhesters I was able to switch languages even without the line that is failing for us... this is a test Header component: import { useTranslation } from "react-i18next";
export default function Header() {
let { t, i18n } = useTranslation();
const changeLanguage = (lng:string) => {
i18n.changeLanguage(lng);
};
return (
<header>
<img src="images/logo.png" title="..." alt="..." />
<section className="languages">
<button onClick={() => changeLanguage('en')}>en</button>
<button onClick={() => changeLanguage('es')}>es</button>
<button onClick={() => changeLanguage('pt-br')}>pt-br</button>
</section>
</header>
);
} works well when I click the buttons... I see the translation changing. |
@heitorsilva You were right, my setup was wrong. Only the |
I have the error too and is happening only with react-i18next ^v12.0.0. I'm sticking with v11 for now ("react-i18next": "^11.18.6"). |
Same issue here after installing latest versions of Remix, I18n and so on. react-i18next:: You will need to pass in an i18next instance by using initReactI18next Removing the line useChangeLanguage works for now, but hope for a solution. Besides that, the new default setup is using hydrate and will revert to React 17. Probably better to replace it with |
Looks like the issue is starts with Though I'd love to see/get this fixed for everyone else, its always nice that you can DIY, Lines 72 to 77 in 91d05bf
You can always put the body of the function in your |
I've been trying to fix it but I couldn't find a way to fix it from |
@sergiodxa It's weird that copying the exact same code fixes the issue. Could it be the way you are defining the dependencies? |
Did some debugging on this, you can see the Replay recording here. The problem comes from mixed ESM and commonjs detection in esbuild. I've opened a PR to change the package.json that worked when I changed it in node_modules. |
could anyone please help me with this error
|
Describe the bug
If you set up a new Remix project one for one as its described in the
README.md
you get the following error:I suspect a bug in the package.
When you comment out the
useChangeLanguage(locale);
hook, it stops this error, however thetitle
string is not translated when you navigate (initial load works). I suspect there are some steps missing in theREADME
.Your Example Website or App
https://github.com/janhesters/remix-i18next-bug
Steps to Reproduce the Bug or Issue
npm i
.npm run dev
.localhost:3000
.useChangeLanguage(locale);
/home
page using the link on the landing page.title
is not translated.Expected behavior
No errors and translation of the
greetings
string.Screenshots or Videos
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: