1

I am upgrading today app to latest nextjs version (10.0.9).

In order to move translates I used next-i18next lib and its simple example from Github.

However, in my app I always get next error: enter image description here

On debugger of next-i18next lib, I found that this error thrown in case of i18n config does not provided.

In my app configurations looks like:

nextjs.config.js nextjs.config.js

next-i18next.config.js enter image description here

_app.js

const HeadstartApp = (props) => {
const { Component, apollo, redux, theme } = props;
  const reduxRef = useRef(initRedux(redux));
  const apolloRef = useRef(
    getApolloClient()
  );
return (
    <React.Fragment>
      <Head>
        <title>Example</title>
        <meta
          name='viewport'
          content='minimum-scale=1, initial-scale=1, width=device-width'
        />
      </Head>
     
      <ApolloProvider client={apolloRef.current}>
        <Provider store={reduxRef.current}>
          <div dir={locale === 'he' ? 'rtl' : 'ltr'}>
            <ThemeProvider theme={createMuiTheme(theme)}>
              {/* <AppBar position={'static'}>
            <Toolbar>
              <Typography>
                <h1>{locale}</h1>
              </Typography>
              <Link href='/projects/construction/1'>
                <Button>Project 1</Button>
              </Link>
              <Link href='/projects/digital/2'>
                <Button>Project 2</Button>
              </Link>
            </Toolbar>
          </AppBar> */}

              <Layout {...props}>
                <Component {...props} />
              </Layout>
            </ThemeProvider>
          </div>
        </Provider>
      </ApolloProvider>
    </React.Fragment>
  );
};
    }
export default appWithTranslation(HeadstartApp);

index.js

const HomePage = (props) => {
...code
}

export const getStaticProps = async ({ locale, defaultLocale }) => ({
  props: {
    ...(await serverSideTranslations(locale || defaultLocale, [
      'common',
      'homepage',
    ])),
  },
});

export default HomePage;

It looks like my app has same configurations as simple example here, but throws this strange exception. Someone got something and can help to solve it

AlexBerd
  • 1,368
  • 2
  • 18
  • 39

1 Answers1

2

That's the solution that works for me:

  • In the _app.js import import i18next.config, like this import NextI18nextConfig from '../../next-i18next.config', this will guarantee that you are loading the configurations.

  • Then exported it in the appWithTranslation, like this export default appWithTranslation(App, NextI18nextConfig)

This will override the default config.

Erick Willian
  • 1,825
  • 11
  • 17