微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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,}
)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?