在vercel上部署Next.js时的错误:位置0的JSON中的意外令牌r
我正在从API中获取JSON数据,如以下
页面/explorer.js,
const charity = await fetch("https://api.www.every.org/api/search_v0?query=&causes="+categories[i]+"&take=100&skip=0", {
method: `GET`,
headers: {
Accept: "application/json"
}
});
const json = await charity.json()
输出的长度很长。我不确定这是原因,但在部署Vercel时会失败。
Error occurred prerendering page "/explorer". Read more: https://nextjs.org/docs/messages/prerender-error
FetchError: invalid json response body at https://api.www.every.org/api/search_v0?query=&causes=coronavirus&take=100&skip=0 reason: Unexpected token R in JSON at position 0
at /vercel/path0/node_modules/node-fetch/lib/index.js:272:32
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async getStaticProps (/vercel/path0/.next/server/pages/explorer.js:331:18)
at async renderToHTML (/vercel/path0/node_modules/next/dist/server/render.js:329:24)
at async /vercel/path0/node_modules/next/dist/export/worker.js:273:36
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:60:20)
I am fetching json data from api like below
-pages/explorer.js
const charity = await fetch("https://api.www.every.org/api/search_v0?query=&causes="+categories[i]+"&take=100&skip=0", {
method: `GET`,
headers: {
Accept: "application/json"
}
});
const json = await charity.json()
It's a bit long length of output. I am not sure that's the reason, but fails while deploying on vercel.
Error occurred prerendering page "/explorer". Read more: https://nextjs.org/docs/messages/prerender-error
FetchError: invalid json response body at https://api.www.every.org/api/search_v0?query=&causes=coronavirus&take=100&skip=0 reason: Unexpected token R in JSON at position 0
at /vercel/path0/node_modules/node-fetch/lib/index.js:272:32
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async getStaticProps (/vercel/path0/.next/server/pages/explorer.js:331:18)
at async renderToHTML (/vercel/path0/node_modules/next/dist/server/render.js:329:24)
at async /vercel/path0/node_modules/next/dist/export/worker.js:273:36
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:60:20)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过添加捕获量避免错误。我找不到更好的方法。
I avoid error by adding catch. I can't find better way.