Next-i18next 初始语言环境参数未传递到 serverSideTranslations

问题描述

它在本地工作。 但是,一旦我将它部署到 firebase 上,它就会产生 nextServer 500 内部错误

next-i18next 版本

8.1.3

配置

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

代码

_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);

关于 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,};
};

解决方法

几天前我遇到了同样的错误,就我而言,根本原因是我的 '.' 文件。我使用的是 next.config.js 并且无法使其与 i18n 的配置一起使用。

我之前是这样设置的:

next-compose-plugins

所以现在我要添加没有 // next.config.js module.exports = withPlugins([ [ withImages({ esModule: true }) ],i18n // error ]) 的配置:

withPlugins

不确定这是否适合您,但出于调试目的,我建议您仅使用 // next.config.js module.exports = withImages({ esModule: true,i18n }) 配置测试您的应用程序。

i18n

我的 // next.config.js module.exports = { i18n } 示例:

next-i18next.config.js
,

使用 next-compose-plugins 时,从他们的 Usage section

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

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

nextConfiguration 应该是配置,意思是一个对象。

所以下面的代码片段应该可以工作:

module.exports = withPlugins(
  [withMdx(mdxConfig)],{
    i18n,}
)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...