gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:50:27 28 4
gpt4 key购买 nike

它在本地工作。
但是,一旦我将它部署在 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文件。我正在使用 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'
}
}

关于next.js - Next-i18next 初始语言环境参数未传递到 serverSideTranslations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67014108/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com