简体   繁体   English

无法加载具有空路径和回退的 static 道具

[英]Failed to load static props with empty paths and fallback

I have the following code on my Dynamic Routing page [id] that I am trying to use with next-i18next translations.我的动态路由页面 [id] 上有以下代码,我正尝试将其与 next-i18next 翻译一起使用。 However, it is throwing an error when being deployed on Vercel (working locally).但是,在 Vercel(本地工作)上部署时会抛出错误。 I am trying to use the fallback function with an empty path array to somehow accept all possible paths(?).我正在尝试使用带有空路径数组的后备 function 以某种方式接受所有可能的路径(?)。 In my console I am getting a statuscode 500 GET-error and a "Failed to load static props"-error.在我的控制台中,我收到状态代码 500 GET 错误和“无法加载 static 道具”错误。

It is working when I specify a specific id within getStaticPaths and go to that matching path.当我在getStaticPaths和 go 中指定特定 id 到该匹配路径时,它正在工作。 However, I can't possibly specify thousands of ids for this to work.但是,我不可能为此工作指定数千个 ID。 Shouldn't the fallback take care of this or how can I get past this?回退不应该解决这个问题,或者我怎样才能克服这个问题?

 export async function getStaticPaths() { return { paths: [], fallback: true } } export async function getStaticProps(context) { return { props: { params: context.params, ...(await serverSideTranslations(context.locale, ["common"])), }, } }

Update: This is the Vercel function log (xxxxx-values is some id's I removed)更新:这是 Vercel function 日志(xxxxx-values 是我删除的一些 id)

 [GET] /_next/data/xxxxxxxxxxx-y/en/packages/490713.json 20:26:37:98 2022-02-28T19:26:39.300Z xxxxxxxxxxxxxxxxxxxxx ERROR Error: ENOENT: no such file or directory, scandir '/var/task/public/locales/en' at Object.readdirSync (fs.js:1047:3) at getLocaleNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:175:23) at /var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:181:20 at Array.map (<anonymous>) at getNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:180:44) at createConfig (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:221:29) at _callee$ (/var/task/node_modules/next-i18next/dist/commonjs/serverSideTranslations.js:199:53) at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:63:40) at Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:294:22) at Generator.next (/var/task/node_modules/regenerator-runtime/runtime.js:119:21) { errno: -2, syscall: 'scandir', path: '/var/task/public/locales/en', page: '/packages/[id]' } RequestId: xxxxxxxxxxxxxxxxxxxx Error: Runtime exited with error: exit status 1 Runtime.ExitError

This line was missing in my next-i18next-config我的 next-i18next-config 中缺少这一行

 localePath: path.resolve('./public/locales'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM