An error occurred during deployment. Please fix:
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Error: connect ECONNREFUSED 127.0.0.1:3306
at R.query (/vercel/path1/.next/server/chunks/364.js:5:60227)
at EB.execute (/vercel/path1/.next/server/chunks/364.js:11:31003)
at Ee.execute (/vercel/path1/.next/server/chunks/364.js:11:20001)
at Ee.then (/vercel/path1/.next/server/chunks/364.js:11:14349)
Export encountered an error on /page: /, exiting the build.
⨯ Static worker exited with code: 1 and signal: null
error: script "build" exited with code 1
Error: Command "bun run build" exited with 1
We're encountering the same database connection error as before, but now it's happening on the homepage. The error occurs because we're trying to fetch recent pastes on the homepage during build time, but there's no database available during the Vercel build process.
Let's fix this by making the homepage dynamic:
I've added export const dynamic = 'force-dynamic' to the homepage, which tells Next.js not to try to prerender this page during build time. Instead, it will render the page on-demand when requested, which means the database connection will only be attempted when the page is actually visited by a user.
This is the same solution we applied to the dashboard page earlier. The error occurs because:
getRecentPastes()By making the page dynamic, we're telling Next.js to skip the static generation step for this page and only render it when requested, at which point it will have access to the actual database configured in your environment variables.
This change should resolve the deployment error while maintaining all the functionality of the homepage.
v8 was created by restoring v5