9

It works locally. However, it will make nextServer 500 internal error once I deployed it on firebase.

next-i18next version

8.1.3

Config

module.exports = {
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'ko'],
  },
};

Codes

_app.tsx

import { appWithTranslation } from 'next-i18next';

const App = ({ Component, pageProps }: AppProps): JSX.Element => {
  return (
    <Provider store={store}>
      <MainWrapper>
        <Component {...pageProps} />
      </MainWrapper>
    </Provider>
  );
};

export default appWithTranslation(App);

code snippets regarding serverSideRendering

export const getStaticProps: any = async ({ locale }) => ({
  props: {
    ...(await serverSideTranslations(locale, [])),
  },
});
export const getServerSideProps: GetServerSideProps = async (context) => {
  const { teamId, email } = context.query;
  let teamName;

  if (!teamId) {
    return { props: {} };
  }

  if (teamId) {
    teamName = await getTeamName(teamId as string);
  }

  return {
    props: {
      teamId,
      teamName,
      email: email || '',
      ...(await serverSideTranslations(context.locale, [])),
    },
  };
};
Ravikumar B
  • 779
  • 1
  • 14
  • 25
Jason Mendoza
  • 91
  • 1
  • 1
  • 3

6 Answers6

13

I had The Same Issue, And Then I remembered that I have to RESTART NEXTJS SERVER MANUALLY after change next.config.js file.

Restart the server helped me.

Tuyen Bui
  • 131
  • 1
  • 3
3

When using next-compose-plugins, from their Usage section,

// next.config.js
const withPlugins = require('next-compose-plugins');

module.exports = withPlugins([...plugins], nextConfiguration);

nextConfiguration should be the configuration, meaning an object.

so the following snippet should work:

module.exports = withPlugins(
  [withMdx(mdxConfig)],
  {
    i18n,
  }
)
Ravikumar B
  • 779
  • 1
  • 14
  • 25
MikeMajara
  • 922
  • 9
  • 23
  • This kept me busy for too long. It's easy to miss that `i18n` **needs to be in the second argument** of `withPlugins`, not in the first argument along with the plugins. – Martijn Jul 06 '21 at 07:25
3

Don't forget to put the key i18n in your next-i18next.config file

NeoZoom.lua
  • 2,269
  • 4
  • 30
  • 64
2

I was having the same error a few days ago and, in my case, the root cause was my next.config.js file. I was using the next-compose-plugins and couldn't make it work with the configurations for the i18n.

That's how I had previously set up:

// next.config.js

module.exports = withPlugins([
  [
    withImages({
      esModule: true
    })
  ],
  i18n // error
])

So now I'm adding the configurations without the withPlugins:

// next.config.js

module.exports = withImages({
  esModule: true,
  i18n
})

Not sure if that will work for you, but for debugging purposes, I'd recommend testing your application using only the i18n configuration.

// next.config.js

module.exports = {
  i18n
}

Example of my next-i18next.config.js:

// next-i18next.config.js

module.exports = {
  i18n: {
    locales: ['pt', 'en-US'],
    defaultLocale: 'pt'
  }
}
gasscoelho
  • 562
  • 5
  • 8
0

I encountered the same problem. I am deploying to App Service in Azure. Here are the thing that I made:

  1. Update the next.config.js

const path = require("path");
require("dotenv").config();
const withPlugins = require('next-compose-plugins')
const { i18n } = require('./next-i18next.config');

const withImages = require("next-images")({
  reactStrictMode: true,
  eslint: {
    dirs: ["apiclients", "common", "components", "config", "pages", "stores"],
  },
  sassOptions: {
    includePaths: [
      path.join(__dirname, "styles"),
      path.join(__dirname, "components"),
    ],
    prependData: `@import "styles/_variables";`, // prepend _css variables in all css documents
  },
  images: {
    domains: [""],
  },
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.plugins.push(new webpack.EnvironmentPlugin(process.env));
    return config;
  },
  experiments: {
    asset: true,
  }
});

const plugins = [withImages];
const nextConfig = { i18n };

module.exports = withPlugins(plugins, nextConfig);
  1. Include next.config.js and next-18next.config.js to the production build of the next JS
  2. Restart the server
0

withPlugins accepts two parameters,first one is array, last one(default) is

a object. you should put i18n into a object list this:

const plugins = [withImages];

const nextConfig = { i18n };

module.exports = withPlugins(plugins, nextConfig);


/**
 * Composes all plugins together.
 *
 * @param {array} plugins - all plugins to load and initialize
 * @param {object} nextConfig - direct configuration for next.js (optional)
 */
const _withPlugins = **([...plugins], nextConfig = {})** => (phase, {
  defaultConfig
}) => {
  ......
};
Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 09 '21 at 16:26