getStaticProps
export async function getStaticProps() {
const apiUrl =
process.env.NODE_ENV !== "production"
? `https://myapp.vercel.app/api/empty`
: "http://localhost:3000/api/empty";
const response = await fetch(apiUrl);
const res = await response.json();
return {
props: {
data: res.message,
},
};
}
api/empty
export default function (req, res) {
res.json({ message: "Hello world!" });
}
this keeps fail to build in vercel
error
Error occurred prerendering page "/empty". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11372:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getStaticProps (/vercel/path0/.next/server/pages/empty.js:105:22)
- info Generating static pages (13/13)
> Export encountered errors on following paths:
/empty
Error: Command "npm run build" exited with 1
how to fix this in production , getStaticProps works well on localhost