Next.js Discord

Discord Forum

dynamic sitemap won't work on deploy

Unanswered
Pacific cod posted this in #help-forum
Open in Discord
Pacific codOP
Hi I have sitemap.ts file like this

import prismadb from '@/libs/prismadb';
import { MetadataRoute } from 'next';

const sitemap = async (): Promise<MetadataRoute.Sitemap> => {
  const courses = await prismadb.course.findMany();
  const coursesEntrites: MetadataRoute.Sitemap = courses.map(
    ({ courseAddressName, updatedAt }) => ({
      url: `rahem.dev/courses/${courseAddressName}`,
      lastModified: updatedAt,
      //   priority: 1,
    })
  );
  return [...coursesEntrites];
};

export default sitemap;


and when I deploy my app it would throw this error and kill the deployment

Error occurred prerendering page "/sitemap.xml". Read more: https://nextjs.org/docs/messages/prerender-error
PrismaClientInitializationError:
Invalid `prisma.course.findMany()` invocation:


error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:7
   |
 6 |   provider = "postgresql"
 7 |   url      = env("DATABASE_URL")
   |

Validation Error Count: 1
    at si.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:125:7117)
    at si.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/library.js:125:6151)
    at si.request (/app/node_modules/@prisma/client/runtime/library.js:125:5859)
    at async l (/app/node_modules/@prisma/client/runtime/library.js:130:9805)
    at async f (/app/.next/server/app/sitemap.xml/route.js:1:606)
    at async v (/app/.next/server/app/sitemap.xml/route.js:1:1082)
    at async /app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:41960


I'm using next 14 and app router. Also Prisma
As you can see the problem seems to be related to prisma. It say "Environment variable not found: DATABASE_URL". But first of all everythings work fine on my local also I add this DATABASE_URL as a Environment Variables with the correct key and value. I should add I'm not deploying to vercel

0 Replies