I created a simple Next.js code that runs fine locally, but has errors during deployment on Vercel:
Use npx create-next-app to create a new Next.js application. Current version is 11.1.0
In pages/index.js add getStaticProps function that gets data from pages/api/hello (the default file created by create-next-app)
import { API_URL } from 'config'; ... export const getStaticProps = async () => { const res = await fetch(
${API_URL}/api/hello
); const data = await res.json();return { props: { data, revalidate: 1, }, }; };
Under the root create config/index.js and write there
export const API_URL = process.env.NEXT_PUBLIC_VERCEL_URL || 'http://localhost:3000';
Full version is available on https://github.com/RayaLevinson/next_js_test
Locally (using npm run dev) works fine.
Deploy on Vercel.7. Build error appears: Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Only absolute URLs are supported
at getNodeRequestOptions (/vercel/path0/node_modules/node-fetch/lib/index.js:1305:9) at /vercel/path0/node_modules/node-fetch/lib/index.js:1410:19 at new Promise (<anonymous>) at Function.fetch [as default] (/vercel/path0/node_modules/node-fetch/lib/index.js:1407:9) at fetchWithAgent (/vercel/path0/node_modules/next/dist/server/node-polyfill-fetch.js:38:39)
at getStaticProps (/vercel/path0/.next/server/pages/index.js:60:21) at renderToHTML (/vercel/path0/node_modules/next/dist/server/render.js:329:30) 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)