5

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

next-i18下一个版本

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, [])),
    },
  };
};
4

6 回答 6

2

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

重启服务器帮了我。

于 2021-09-09T11:19:07.327 回答
1

使用 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,
  }
)
于 2021-05-24T17:07:25.270 回答
1

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

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

// 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-i18next.config.js

module.exports = {
  i18n: {
    locales: ['pt', 'en-US'],
    defaultLocale: 'pt'
  }
}
于 2021-04-12T23:24:51.713 回答
0

我遇到了同样的问题。我正在部署到 Azure 中的应用服务。这是我做的东西:

  1. 更新下一个.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. 将 next.config.js 和 next-18next.config.js 包含到下一个 JS 的生产构建中
  2. 重启服务器
于 2021-10-19T19:10:29.550 回答
0

withPlugins 接受两个参数,第一个是数组,最后一个(默认)是

一个对象。你应该把 i18n 放到一个对象列表中:

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
}) => {
  ......
};
于 2021-12-09T13:27:08.237 回答
0

不要忘记将密钥i18n放入您的next-i18next.config文件中

于 2021-12-07T09:38:36.920 回答