jcm10
jcm10
Explore posts from servers
PPrisma
Created by jcm10 on 1/10/2025 in #help-and-questions
Prisma Optimize Initialization Missing Database URL
After waiting 2 hours for migrations, I decided to give Optimize a go. I have my database url in my .env.development file, which works great when initializing my prisma clients in other files, the DB services. However, it can't find it on my index file.
// prettier-ignore
import dotenv from 'dotenv';
dotenv.config();

import { PrismaClient } from "@prisma/client";
import { withOptimize } from "@prisma/extension-optimize";

if (process.env.OPTIMIZE_API_KEY && process.env.DATABASE_URL) {
console.log(process.env.DATABASE_URL);
new PrismaClient().$extends(
withOptimize({ apiKey: process.env.OPTIMIZE_API_KEY})
)
}
// prettier-ignore
import dotenv from 'dotenv';
dotenv.config();

import { PrismaClient } from "@prisma/client";
import { withOptimize } from "@prisma/extension-optimize";

if (process.env.OPTIMIZE_API_KEY && process.env.DATABASE_URL) {
console.log(process.env.DATABASE_URL);
new PrismaClient().$extends(
withOptimize({ apiKey: process.env.OPTIMIZE_API_KEY})
)
}
Here is the error that gets printed:
PrismaClientInitializationError: error: Environment variable not found: DATABASE_URL.
PrismaClientInitializationError: error: Environment variable not found: DATABASE_URL.
However, if I remove the prisma code from this file and log the process.env.DATABASE_URL, it prints out no problem. The script I am running when the error occurs is this:
./node_modules/.bin/dotenv -e .env.development -- ts-node src/index.ts
./node_modules/.bin/dotenv -e .env.development -- ts-node src/index.ts
6 replies