首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Next-i18next初始区域设置参数未传递到serverSideTranslations

Next-i18next初始区域设置参数未传递到serverSideTranslations
EN

Stack Overflow用户
提问于 2021-04-09 10:00:42
回答 6查看 2.9K关注 0票数 4

它在本地工作。然而,一旦我把它部署到firebase上,它就会导致nextServer 500内部错误。

next-i18next版本

8.1.3

配置

代码语言:javascript
复制
module.exports = {
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'ko'],
  },
};

代码

_app.tsx

代码语言:javascript
复制
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的代码片段

代码语言:javascript
复制
export const getStaticProps: any = async ({ locale }) => ({
  props: {
    ...(await serverSideTranslations(locale, [])),
  },
});
代码语言:javascript
复制
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, [])),
    },
  };
};
EN

回答 6

Stack Overflow用户

发布于 2021-09-09 11:19:07

我有同样的问题,然后我记得我必须在更改next.config.js文件后手动重启NEXTJS服务器。

重启服务器帮了我大忙。

票数 2
EN

Stack Overflow用户

发布于 2021-04-13 07:24:52

几天前我也遇到了同样的错误,在我的例子中,根本原因是我的next.config.js文件。我使用的是next-compose-plugins,无法使其与i18n的配置一起工作。

这就是我之前设置的方法:

代码语言:javascript
复制
// next.config.js

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

所以现在我要添加不带withPlugins的配置

代码语言:javascript
复制
// next.config.js

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

我不确定这是否适用于您,但出于调试目的,我建议您仅使用i18n配置测试您的应用程序。

代码语言:javascript
复制
// next.config.js

module.exports = {
  i18n
}

我的next-i18next.config.js示例

代码语言:javascript
复制
// next-i18next.config.js

module.exports = {
  i18n: {
    locales: ['pt', 'en-US'],
    defaultLocale: 'pt'
  }
}
票数 1
EN

Stack Overflow用户

发布于 2021-05-25 01:07:25

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

代码语言:javascript
复制
// next.config.js
const withPlugins = require('next-compose-plugins');

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

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

因此,下面的代码片段应该可以工作:

代码语言:javascript
复制
module.exports = withPlugins(
  [withMdx(mdxConfig)],
  {
    i18n,
  }
)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67014108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档