PrismaP
Prisma5mo ago
6 replies
DaanDeReus

PrismaClientInitializationError]: error: Environment variable not found: DATABASE_URL.

I really need help, i spent like 2 hours now on this and i just cant fix it.

1. I am on the latest's version of the client
2. I have checked, i have a .env in root and it has DATABASE_URL in it
3. I tried using the new prisma.config.ts (and without):
import type { PrismaConfig } from "prisma";

// import your .env file
import "dotenv/config";

export default {
  schema: "prisma/",
} satisfies PrismaConfig;

Still same error...

This is my main schema:
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  output          = "../../node_modules/.prisma/client"
  previewFeatures = ["queryCompiler", "driverAdapters"]
}


This is how i initialise it:
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '@prisma/client';
import { withAccelerate } from '@prisma/extension-accelerate';
import { withOptimize } from '@prisma/extension-optimize';
import { attachDatabasePool } from '@vercel/functions';
import { Pool } from 'pg';

const pool = new Pool()

attachDatabasePool(pool)

const db = new PrismaClient({
  adapter: new PrismaPg(pool)
})
  .$extends(withOptimize({ apiKey: process.env.OPTIMIZE_API_KEY || "" }))
  .$extends(withAccelerate());

export default db;

I use these pool things from the docs. It is becouse i am deploying to Vercel. And vercel was giving some weird issues that i was trying to resolve. But now i have these issues.

The prior issues that lead to me upgrading the @prisma/client version and having these problems:
Type error: Module '"@prisma/client"' has no exported member 'EventDate'.
> 5 | import { EventDate, EventShift, Prisma } from "@prisma/client";
Next.js build worker exited with code: 1 and signal: null


It says no exported member. While it does, ofcouse. Locally it DOES build and export the types. So idk why it didnt on vercel. So i just updated the client in hopes of fixing it. But now got more problems
Was this page helpful?