[英]Error while deploying Next.js on vercel: Unexpected token R in JSON at position 0
I am fetching json data from api like below我正在从 api 获取 json 数据,如下所示
-pages/explorer.js -页面/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. output 的长度有点长。我不确定是这个原因,但是在 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 avoid error by adding catch.我通过添加 catch 来避免错误。 I can't find better way.我找不到更好的方法。
try{
const json = await charity.json()
} catch(err) {
console.log("err: ", err)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.