Next-i18next: Issue with basic implementation

Created on 18 Jun 2019  路  6Comments  路  Source: isaachinman/next-i18next

Hello everybody,

I tried to implement this package into my setup which is heavily inspired by this repo https://github.com/atherosai/next-react-graphql-apollo .
But even by exactly following the instructions from the readme I always get an error message on the server side, which reads as follows:
react-i18next:: You will need pass in an i18next instance by using initReactI18next

Nevertheless the code works and translations are applied. Additionally I get a console error on page load, with the content:
Warning: Expected server HTML to contain a matching

in
.
This error only appears after using this package and was never seen before.

Does anyone maybe have an idea, what could cause the issues?

Thanks in advance!

Best regards, Patrick

Most helpful comment

@patsa we had the same error message when we added react-i18next as direct dependency in our package.json and imported their useTranslation hook for example.

In that case we had to something like this:

import { initReactI18next } from 'react-i18next';
const NextI18NextInstance = new NextI18Next({
...
use: [initReactI18next]
}

Need to mention that we are on Typescript and we ran into follow up issues with error messages that i18n.languages would be undefined.

But since this lib exports that hook itself we rolled back and haven't those issues anymore, obviously.

All 6 comments

I might as well try to create a repo that reproduces the issues and share it with you later today.

Yes, please do. Can't really help without a reproducible repo, as there are way too many factors in play.

@patsa we had the same error message when we added react-i18next as direct dependency in our package.json and imported their useTranslation hook for example.

In that case we had to something like this:

import { initReactI18next } from 'react-i18next';
const NextI18NextInstance = new NextI18Next({
...
use: [initReactI18next]
}

Need to mention that we are on Typescript and we ran into follow up issues with error messages that i18n.languages would be undefined.

But since this lib exports that hook itself we rolled back and haven't those issues anymore, obviously.

@isaachinman
I published a repository with an example implementation based on the system I'm using for my real app too.
https://github.com/patsa/react-next-i18next-example-application
I temporarily added you as a collaborator. Feel free to check the code out.
Currently next-i18next isn't working at all (with the same setup as in my original code where it works).

A couple of points to hopefully help you in the future:

  1. This is not "basic implementation"
  2. This is not a minimal reproducible example

That aside, the error is straightforward:

Error while running `getDataFromTree` TypeError: Cannot read property 'i18n' of undefined

If you do some basic Googling and/or searching of issues in this repo and Apollo, you'll quickly see this is due to tree traversal and most likely reflects invalid context as your original comment also indicates.

Good luck to you - this is not something that next-i18next is willing/able to help debug as it involves the use of several different packages. That said, there are many users who have combined Apollo with next-i18next. Perhaps try on StackOverflow or Spectrum.

@patsa we had the same error message when we added react-i18next as direct dependency in our package.json and imported their useTranslation hook for example.

In that case we had to something like this:

import { initReactI18next } from 'react-i18next';
const NextI18NextInstance = new NextI18Next({
...
use: [initReactI18next]
}

Need to mention that we are on Typescript and we ran into follow up issues with error messages that i18n.languages would be undefined.

But since this lib exports that hook itself we rolled back and haven't those issues anymore, obviously.

Thanks, that fixed my issue. I'm wondering why this is needed as I didn't need to do this before I convert to typescript

Was this page helpful?
0 / 5 - 0 ratings