react-i18next:: You will need to pass in an i18next instance by using initReactI18next when running build when there is translation in top level layout
See original GitHub issue🐛 Bug Report
This is only happening when I run build
script and my layout call useTranslation
hook
To Reproduce
A small repo to reproduce
- clone the repo, install deps
- run
pnmp run build
you’ll see the warning
This is the only place I call useTranslation hook
// My _app.tsx
import "../styles/globals.css";
import type { AppProps } from "next/app";
import { appWithTranslation, useTranslation } from "next-i18next";
import React from "react";
function MyApp({ Component, pageProps }: AppProps) {
return (
<Layout>
<Component {...pageProps} />
</Layout>
);
}
const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { t } = useTranslation();
return (
<div>
<div>{t("hello-world")}</div>
{children}
</div>
);
};
export default appWithTranslation(MyApp);
my only page is pages/index.tsx
and I already called the serverSideTranslation
export async function getStaticProps({ locale }: any) {
return {
props: {
...(await serverSideTranslations(locale, ["common"])),
},
};
}
the translation is working, and I believe as mentioned here https://github.com/i18next/next-i18next/issues/1840#issuecomment-1145614232
the only issue is that there are warnings happen when running build
Expected behavior
There’s no warning that says react-i18next:: You will need to pass in an i18next instance by using initReactI18next
when running build script
Your Environment
- runtime version: node v16.13.2,
- next-i18next version: v11.3.0
- os: Windows
- next: latest
Issue Analytics
- State:
- Created a year ago
- Reactions:11
- Comments:77 (26 by maintainers)
Top Results From Across the Web
You will need to pass in an i18next instance by using ...
Meaning you 'll need to add serverSideTranslation to the pages that need translations. For example in your pages/d/[tab]/index file: import Head ...
Read more >Step by step guide - react-i18next documentation
use (initReactI18next) we pass the i18n instance to react-i18next which will make it available for all the components. Then import that in index....
Read more >How to properly internationalize a React application using ...
Prerequisites. Make sure you have Node.js and npm installed. It's best, if you have some experience with simple HTML, JavaScript and basic React....
Read more >A Guide to React Localization with i18next | Phrase
I18next is also “learn once—translate everywhere”: You can use it with many ... Our <App> component provides high-level layout and comprises a <Navbar>...
Read more >next-i18next - npm
There are 86 other projects in the npm registry using next-i18next. ... If you want to structure your translations/namespaces in a custom ...
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
Update: v13.0.0 is released and might partially fix this issue by moving i18next, react-i18next to peer-deps.
There’s a new TROUBLESHOOT document to help with installation, specifically: You will need to pass in an i18next instance
If you experienced issues before, could you try v13.0.0 and let me know ?
PS: I’m planning to tackle the dual packaging hazards in the upcoming weeks.
Then probably we have to live with that warning… The problem is, during build, the Layout component is rendered also if i18next is not initialized yet and not ready…
If you do this, you’ll see what I mean. But I honestly have no idea how to prevent this in next.js, sorry.