将Siserverside翻译添加到我的Next.js应用程序时出错
在将应用程序部署到Vercel时,我会遇到错误,但是我的应用程序在本地服务器上的工作正常。 这是我的功能日志看起来像
TypeError: Cannot read properties of undefined (reading '__NEXT_DATA__')
at Document (/var/task/.next/server/pages/_document.js:24:26)
Error: ENOENT: no such file or directory, scandir '/var/task/public/locales/en'
我的_document.js
export default function Document(props) {
const locale = props.__NEXT_DATA__.locale;
console.log(props.__NEXT_DATA__);
const dir = locale === "ar" ? "rtl" : "ltr";
return (
<Html dir={dir} lang={locale}>
<Head />
<body className={locale === "ar" ? "rtl" : null}>
<Main />
<NextScript />
</body>
</Html>
);
}
I am getting an error when deploying my app to vercel, but my app work perfectly fine on local server.
Here is what my function logs looks like
TypeError: Cannot read properties of undefined (reading '__NEXT_DATA__')
at Document (/var/task/.next/server/pages/_document.js:24:26)
Error: ENOENT: no such file or directory, scandir '/var/task/public/locales/en'
my _document.js
export default function Document(props) {
const locale = props.__NEXT_DATA__.locale;
console.log(props.__NEXT_DATA__);
const dir = locale === "ar" ? "rtl" : "ltr";
return (
<Html dir={dir} lang={locale}>
<Head />
<body className={locale === "ar" ? "rtl" : null}>
<Main />
<NextScript />
</body>
</Html>
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案,我必须在配置文件中指定我的Locales文件夹,这样
I found the answer, I had to specify my locales folder in my config file like so