-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
react-i18next:: i18n.languages were undefined or empty undefined #374
Comments
Are you sure Please provide reproducible repo. |
I believe I'm getting the same error when using i18n.language for a select value. The value is undefined on the server and correct on the client, so it flickers on load. |
Does anyone have a reproducible example? |
I have the same problem,Have you solved it? |
@isaachinman Here is the repo. You’ll see a warning initially
And then
I also added In my actually project, I have error page and |
@mehmetnyarar I have cloned your repo and run it. I do see the I do not see the Does anyone have a reproducible example? |
I'm getting this warning when just running simple example (build & start) "next": "^8.1.0", |
@deemaagog I cannot reproduce that either. Can you zip your directory, including |
I also have this error in a ts project with a custom server, but only in this case:
Sometimes, the recompile finishes before the hot module request, and the error page doesn't get generated, and everything is ok, but that might be a 1 out of 10 occurrence. Using next 8.1.0 and ni18n 0.44.0 |
@mslepcevic Thanks for that information. @mehmetnyarar Is this a dev-only error, or are you experiencing problems in production? Sounds like this could be a userland dev setup issue. |
@isaachinman And the HMR request comes in because of the page that's opened in the browser and wants to reload upon saving a file. |
I'm also experiencing the same issue, even in production. I haven't had the time yet to create a reproducible repository tho. I can recall that i've only seen the warning when using the following setup to determine the language: const currentLanguage = typeof req === "undefined" ? i18n.language : req.language; (in _app.js && _document.js). Could it be that it's sometimes not waiting for the response and thus triggers the warning? |
Here is a zip |
Thanks @deemaagog I've finally seen this reproduced. It's coming from I will dig into this now, but it looks like a harmless warning, unless I'm mistaken. |
So although I saw the error one time, I cannot reproduce it reliably and have not seen it since then. If this is a race condition, I'm not sure where it is. It seems like this would be caused by a call to |
@isaachinman first of all, thanks for the plugin :) |
@urielscola Multiple problems with your repo which are unrelated:
That said, even if I run |
@isaachinman thanks, you were absolutely right. I fixed those problems and now it is working |
I got the same issue because I just use footer:description only, but I called both common and footer,
I tried to remove 'common. But the issue still happen. I'm not sure why the 'common' translation is a must.
Then the issue is resolved. |
@ilhammeidi Can you please provide a reproducible repository? |
Here's my file and repo https://github.com/ilhammeidi/luxi-react-starter/blob/master/pages/index.js I'm still testing about "react-i18next:: i18n.languages were undefined or empty undefined" message that sometime show in console. After ctrl+shit+r in chrome and restart server, it's gone already. |
Okay, please let me know if you discover a reliable way to reproduce it. |
Hi, |
I see 2 possible issues
|
@ricardo-cantu Thanks for your input. Indeed it'd be good if we can await the promise returned by Can you explain your second point in more detail? The mysterious |
@isaachinman Thanks for the awesome work you've done with this library. I wrote my own implementation in typescript based on your work (I left out several things I didn't need)
|
I'm hesitant to go down this road, as we are really trying to get closer to serverless support. As for the second point, |
You can simply show an example of wrapping the application with a top level function. There's already an example of index.ts -> server.ts somewhere in next.js examples.
When you say serverless, do you mean no node server like express? |
@isaachinman I have the same problem. |
@gtolarc That's very helpful, thank you! If I set |
@oteka21 Please see the source. |
Same issue here with latest versions. Site seems to render with:
as @truongtx9 proposed above. What's this ? Is this a bug or a non documented feature ? |
@rdewolff As stated previously, that will break language detection. |
Facing the same issue, there is a way to solve this without breaking the language detection? |
+1 |
Yes, either await the promise returned by the i18next |
so do you know a solution or what is the state here? How can I help? |
@StarpTech The working assumption is that it's a race condition on startup. The only way we can arrive at a non-breaking-change solution is if we can find a way to initialise an i18next instance synchronously. |
If that helps, let me describe my solution to the problem.
So here is solution in my case - change ignoreRoutes to empty array: const NextI18Next = require('next-i18next').default;
const { localeSubpaths } = require('next/config').default().publicRuntimeConfig;
const localeSubpathVariations = {
none: {},
foreign: {
fr: 'fr',
en: 'en',
},
all: {
en: 'en',
fr: 'fr',
},
};
module.exports = new NextI18Next({
defaultLanguage: 'ru',
otherLanguages: ['fr', 'en'],
localeSubpaths: localeSubpathVariations[localeSubpaths],
debug: true,
// initImmediate: true,
// load: 'all',
ignoreRoutes: [],
}); @isaachinman not sure if there's any race condition in |
Setting For anyone wishing to help on this issue: please take a deep dive before bumping or offering suggestions! |
@isaachinman Not sure if it is of any help, but for me the problem seems to occur when I'm having a custom route, e.g.: custom route: router.get('/password-renew/:passwordResetSlug', helmet.noCache(), (req, res) => {
const actualPage = '/password-renew';
const queryParams = { ...req.query, passwordResetSlug: req.params.passwordResetSlug }
return app.render(req, res, actualPage, queryParams);
}) page: class RenewPasswordPage extends Component {
static async getInitialProps(ctx) {
const namespacesRequired = ['public']
const passwordResetSlug = ctx.query.passwordResetSlug
return { namespacesRequired, passwordResetSlug }
}
render() {
// ...
}
}
export default withTranslation('public')(RenewPasswordPage) |
Not sure if I'm helping but I caught this error from my side too and I temporary fix it by adding languages propriety to i18n object. const languages = ['fr-FR', 'en-GB'];
const options = {
defaultLanguage: 'fr-FR',
otherLanguages: ['en-GB'],
...
};
const NextI18NextInstance = new NextI18Next(options);
NextI18NextInstance.i18n.languages = languages;
module.exports = NextI18NextInstance; |
Using @jonathangiamp worked after adding the |
Correct me if I'm wrong but if the root issue is really the way how we bootstrap i18n then we should release a breaking change to fix that correctly. |
@StarpTech If and when it is determined that we cannot initialise an i18next instance synchronously, then yes, we'd need to release a breaking change. This is a very good example of a use case where we definitely want to init an instance synchronously, as our application cannot serve any requests until it's ready. @jamuhl Any ideas about what we might be doing wrong here? Any opinion about construction/initialisation? Funny that this issue has become so popular. |
@isaachinman please add "bug" label |
@isaachinman would be happy to help with this...but I do not get the issue
but why is that a problem in production...a server starts up and things will be ready on first request...or even delay start of server and start it inside the init callback... for serverless add a middleware that asserts init is done before calling next should do the trick (just use the initialized event and flag on i18next.) |
Looks like this might happen more often when you have a custom _error that uses t() or the hoc. Next will compile a _error page with no req, thus no i18n object that has the correct lang detected. I removed the custom _error in another project I’m working on and I have not seen the warning again. |
Finally took some time to dig into this. The issue of awaiting the initialisation of the i18next instance is a very trivial one, and I can provide an easy, non-breaking way for users to do that if they want to. However, I think that that race condition is causing a very low percentage of the error reports we are seeing here. The main problem is indeed with 404s, primarily in development. This is because a browser makes a request for a dev resource which used to exist, but now has been cleared by HMR. Eg:
This request goes through the The request then gets passed to NextJs: const handle = app.getRequestHandler()
server.get('*', (req, res) => handle(req, res)) At this point the request is determined to be a 404, and the status code is changed. At that point in time, NextJs wants to render an error page, but does so without a redirect (naturally), so the That NextJs logic can be found here. (It's noteworthy that this code path is different than "normal", non-resource, 404s which The curious part is how In general this is a bit of a chicken-and-egg problem to solve. The easy thing to do is to remove the passing of The actual redirect logic is protected by However, this solution would mean that we are processing all our static resource requests through the i18next middleware, just on the off chance that one of them results in a 404. Perhaps this is actually the right thing to do? No idea if this has perf implications, but it probably does. On a side note, I have no idea why the NextJs team have decided to return an HTML doc for a 404 on a JSON resource - that doesn't seem right to me. Not sure if that's configurable. Apologies for a long post, but that's the entire story. We have all the information necessary to work on this, it's just a matter of discussing amongst ourselves what makes the most sense. Open for discussion. |
Thanks to OP and @isaachinman for taking time to check this issue.
What would be the quick-fix? Thanks |
There is no "quick-fix" in user land, it needs to happen within the source code. |
I get this problem when I use My locales folder:
Instance:
|
localePath: typeof window === 'undefined' ? 'public/static/locales' : 'static/locales' |
Describe the bug
I get the the following error:
which appears only on the server (I mean in the output of the terminal, it doesn’t appear on the browser console).
Occurs in next-i18next version
"next": "^8.1.0",
"i18next": "^17.0.6",
"next-i18next": "^0.44.0",
Steps to reproduce
I followed every step described in the readme except
keySeparator
(because I have keys likeStatus.ONGOING
)Below is my configuration:
Expected behaviour
This doesn’t look like a critical error, though I’m wondering the cause.
Screenshots
OS (please complete the following information)
Additional context
The text was updated successfully, but these errors were encountered: