You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DATABASE_URL is required for prisma generate in v7 #28590
We were generating prisma client in our CI pipeline in order to perform typechecking. After the update to v7, the pipeline breaks with Error: PrismaConfigEnvError: Missing required environment variable: DATABASE_URL.
I didn't see any mention of DATABASE_URL being now required for prisma generate command in the docs. I don't even see a reason why it should be.
Reacted by Ilja Mulders, Bennet Gallein, Benoit Travers, Viktor, Nauris Steins, Eric Cabrel TIOGO, Seren_Modz 21, Lure5134, David Jebing, Michał Ciężczak and 44 more
Reacted by leppaott, Jesus Escalona, Daniel Haupt and Rob
Even after updating the Prisma package to version 7, the client may still be running version 6. Delete the generate folder completely and regenerate the client. Or you can also remove the prisma packages from node_modules and reinstall them, after generate new client
I'm talking about CI pipeline. There is nothing to delete...
every prisma CLI command reads the Prisma config file (e.g., prisma.config.ts)
most commands use at least one of the possible attributes that can be set in prisma.config.ts
only some of these commands actually need the datasource.url value, especially prisma db *, prisma migrate *, and prisma generate --sql
prisma generate, per se, doesn't need any URL do be generated. However, if env() is given a non-defined env var, loading prisma.config.ts will result in a runtime error (you can see how env works here). And since any prisma commands loads it (including prisma generate), you're facing the error reported.
@iljamulders has the right solution: #28590 (comment).
If your environment variable isn't guaranteed to exist, you should not use the env() utility from prisma/config.
We'll improve our docs to clarify this. Thanks!
Reacted by Ilja Mulders, hubts, Yashu Mittal, Gianni, Michael Kesper, Daniel Haupt, ccompas34 and Einar Skreslett
That isn't done yet, is it? I'm wondering if there's a clever way to detect that the config is loaded. Then something like this would work to make the environment variable required exactly when needed:
import'dotenv/config';import{defineConfig,env,PrismaConfig}from'prisma/config';functiondatasource(cb: ()=>PrismaConfig['datasource']){constneedsDatasource=false;// <--- How to determine if we need a datasource?returnneedsDatasource ? {datasource: cb()} : {};}exportdefaultdefineConfig({schema: 'prisma/schema.prisma',migrations: {path: 'prisma/migrations',},
...datasource(()=>({url: env('DATABASE_URL'),shadowDatabaseUrl: process.env.SHADOW_DATABASE_URL,})),});
or
import'dotenv/config';import{defineConfig,env}from'prisma/config';constneedsDatasource=false;// <--- How to determine if we need a datasource?exportdefaultdefineConfig({schema: 'prisma/schema.prisma',migrations: {path: 'prisma/migrations',},datasource: needsDatasource
? {url: env('DATABASE_URL'),shadowDatabaseUrl: process.env.SHADOW_DATABASE_URL,}
: undefined,});
Of course the helper constant/function should be provided for this to be easily usable.
The .env file with the connection string is gitignored causing the CI pipeline (Github Actions) for tests and builds to fail because it can't locate the file. Previously it was no issue because it would just read the env file during introspect.
Realized I don't need the .env file anymore when I use the new configuration as I can just create the connection string directly using our Google Cloud integration. Build now fails during generate because CI pipeline is not authenticated with the Google Cloud Project, which it shouldn't need except for during introspection.
I have resolved this issue by providing the fake connection string in my git pipeline while building the container image. This resolves my problem.
# Provide a safe placeholder DATABASE_URL at build-time so Prisma config can load
# without requiring real credentials (only used for `prisma generate` during build).
# You can override this at build with:
# docker build --build-arg PRISMA_GENERATE_DATABASE_URL="postgresql://user:pass@host:5432/db?schema=public" \
# -f Dockerfile.prod -t backend:latest .
I have resolved this issue by providing the fake connection string in my git pipeline while building the container image. This resolves my problem.
# Provide a safe placeholder DATABASE_URL at build-time so Prisma config can load
# without requiring real credentials (only used for `prisma generate` during build).
# You can override this at build with:
# docker build --build-arg PRISMA_GENERATE_DATABASE_URL="postgresql://user:pass@host:5432/db?schema=public" \
# -f Dockerfile.prod -t backend:latest .
Wouldn't just allowing the datasource-url to be a function resolve the issue? In that case the env file is not read except when needed, which in my case means I don't need the env file in the CI pipeline just because it needs to exist in the config as a string.
Reacted by Jaden, Kincaid O'Neil, Martin Klinke, Michael Kesper and Bo Lingen
Another way to look at this is the fact that only prisma migrate does not accept a custom db url via --url:
prisma generate does not require a datasource
prisma migrate needs a datasource
@prisma/client takes an instance of an adapter anyway
Perhaps, at least for some of us, the solution is simply to add support for --url on prisma migrate and then remove datasource from the prisma.config.ts completely.
Hello, I'm dealing with DATABASE_URL right now and this issue seems to be the closest to mine.
I'm containerizing two Prisma-powered apps, but there are opposing issues and solving one creates the other.
Keep it as default
If, as stated by the generated prisma.config.ts, the project has dotenv as a dev. dependency, then the npx prisma migrate deploy doesn't work when running the container because by loading the prisma.config.ts it will need dotenv, which is a dev. dependency (and because I'm deploying production, it is not installed).
Solution for the container
The container doesn't have dotenv, so if I remove the import from the prisma.config.ts file, then it works.
The problem now is that running the npx prisma commands locally is cumbersome, as I don't have the environments variables defined in my machine (and as I'm developing diferent applications, it would drive me crazy to change for each of them manually)
Ideas I have yet to try
Installing dotenv as a full dependency
It seems absurd to add a dependency to a container image just to NOT use it.
Also, as I researched on the .env file topic, I read a lot of advise against using dotenv or .env files in general and specially in production.
Containerize the development environment too.
It would technically work, but I feel it would render useless some features from my frameworks (like hot reloading).
Changing prisma.config.ts to, instead of using dotenv, checking if variables exist and, if they don't, load them from a .json file or similar.
I'm leaning towards this one because I feel it is "natural", but then I wonder why it is not the default.
I feel like I might be missing something, because if dotenv is supposed to be a dev. dependency maybe I should not be trying to run npx prisma migrate deploy from production, but I've thought of all the possibilities and can not reach a conclussion by myself.
I ended up changing my Prisma config to a .js file, so it doesn't need to be compiled. This, combined with not using the env() method, but just using process.env.DATABASE_URL.
When I run prisma generate --sql to generate typed sql it's worse. It requires the datasource.url and it needs it to be a proper connection string because it actually connects to the database. Not sure why that was the design choice and not just generate based on the schema files.
I ended up changing my Prisma config to a .js file, so it doesn't need to be compiled. This, combined with not using the env() method, but just using process.env.DATABASE_URL.
Hope this helps.
Sorry, but I can't see how it would help. I'm already not using the env() method, but if the dependency to dotenv remains, what does it matter if it is compiled or not?
I was missing the config file in my final Docker runtime stage. This didn't have tsc or tsx to compile to the .ts Config. Although, I'm not a 100% sure this was the issue as I also had a typo in the path where I copied the config to 🤡
This is exactly what safelaunch catches it validates that DATABASE_URL and all your other required env variables are present before you run any commands or push to production. Would have flagged this immediately.
This is exactly what safelaunch catches it validates that DATABASE_URL and all your other required env variables are present before you run any commands or push to production. Would have flagged this immediately.
This doesn't address the core problem of the issue, which is that generating code with prisma generate should not need to have the env. variable defined
With Prisma 7.8.0 (and maybe earlier) datasource.url may in fact be undefined so you can just use process.env.DATABASE_URL without any compile errors. If DATABASE_URL is not defined
npx prisma generate works fine (as desired), and
npx prisma migrate dev properly reports
Error: The datasource.url property is required in your Prisma config file when using prisma migrate dev.
I'd argue this issue is solved while the proposed usage of env("DATABASE_URL") in the docs and migration guide is still misleading.
In my case VS Code/LSP still reports error
Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node and then add 'node' to the types field in your tsconfig.ts(2591)
since my tsconfig.json contains "include": ["src/**/*"],. This is not related to Prisma though, and npx prisma generate works nonetheless.
Activity
jakub-msqt commentedon Nov 20, 2025
I'm talking about CI pipeline. There is nothing to delete...
iljamulders commentedon Nov 20, 2025
Same issue for us.
The prisma.config.ts needs the env DATABASE_URL for migrations, but not for the generate command.
For now, instead of the using the example from Prisma:
We just do:
jakub-msqt commentedon Nov 20, 2025
@iljamulders Nice one. I did a hot fix like:
DATABASE_URL=test prisma generate, but yours is cleaner.YasserMountij commentedon Nov 21, 2025
@iljamulders thanks dude for the solution , i dont see the need to require env when generating types
anaelChardan commentedon Nov 21, 2025
Same issue!
jkomyno commentedon Nov 24, 2025
Hi @jakub-msqt, to clarify:
prismaCLI command reads the Prisma config file (e.g.,prisma.config.ts)prisma.config.tsdatasource.urlvalue, especiallyprisma db *,prisma migrate *, andprisma generate --sqlprisma generate, per se, doesn't need any URL do be generated. However, ifenv()is given a non-defined env var, loadingprisma.config.tswill result in a runtime error (you can see howenvworks here). And since anyprismacommands loads it (includingprisma generate), you're facing the error reported.@iljamulders has the right solution: #28590 (comment).
If your environment variable isn't guaranteed to exist, you should not use the
env()utility fromprisma/config.We'll improve our docs to clarify this. Thanks!
rovo89 commentedon Nov 27, 2025
That isn't done yet, is it? I'm wondering if there's a clever way to detect that the config is loaded. Then something like this would work to make the environment variable required exactly when needed:
or
Of course the helper constant/function should be provided for this to be easily usable.
leppaott commentedon Nov 28, 2025
Command failed: prisma db execute --file ..migration.sql --url postgresql://post....." as a TypeScript/JavaScript module. Error: PrismaConfigEnvError: Missing required environment variable: DATABASE_URLUm
db executefails too even though it uses--urlOk seems they dropped that flag but docs still have it: https://fig.io/manual/prisma/db/execute
dbengtsson commentedon Dec 1, 2025
I am facing issues with this as well.
generatebecause CI pipeline is not authenticated with the Google Cloud Project, which it shouldn't need except for during introspection.Zaeem6100 commentedon Dec 2, 2025
I have resolved this issue by providing the fake connection string in my git pipeline while building the container image. This resolves my problem.
PRISMA_GENERATE_DATABASE_URL="postgresql://placeholder:placeholder@localhost:5432/placeholder?schema=public"SerenModz21 commentedon Dec 2, 2025
Note: the placeholder doesn't have to be a full Postgres URL. It can contain any value (e.g. DATABASE_URL=no).
The
env()helper does not validate the value; it just checks if it exists.Source: https://github.com/prisma/prisma/blob/main/packages/config/src/env.ts
dbengtsson commentedon Dec 2, 2025
Wouldn't just allowing the datasource-url to be a function resolve the issue? In that case the env file is not read except when needed, which in my case means I don't need the env file in the CI pipeline just because it needs to exist in the config as a string.
chore: migrate to Prisma v7
chore: migrate to Prisma v7
2 remaining items
shimonenator commentedon Dec 18, 2025
Another way to look at this is the fact that only
prisma migratedoes not accept a custom db url via--url:prisma generatedoes not require a datasourceprisma migrateneeds a datasource@prisma/clienttakes an instance of an adapter anywayPerhaps, at least for some of us, the solution is simply to add support for
--urlonprisma migrateand then removedatasourcefrom theprisma.config.tscompletely.AndresCasado commentedon Feb 6, 2026
Hello, I'm dealing with
DATABASE_URLright now and this issue seems to be the closest to mine.I'm containerizing two Prisma-powered apps, but there are opposing issues and solving one creates the other.
Keep it as default
If, as stated by the generated
prisma.config.ts, the project hasdotenvas a dev. dependency, then thenpx prisma migrate deploydoesn't work when running the container because by loading theprisma.config.tsit will needdotenv, which is a dev. dependency (and because I'm deploying production, it is not installed).Solution for the container
The container doesn't have
dotenv, so if I remove theimportfrom theprisma.config.tsfile, then it works.The problem now is that running the
npx prismacommands locally is cumbersome, as I don't have the environments variables defined in my machine (and as I'm developing diferent applications, it would drive me crazy to change for each of them manually)Ideas I have yet to try
dotenvas a full dependency.envfile topic, I read a lot of advise against usingdotenvor.envfiles in general and specially in production.prisma.config.tsto, instead of usingdotenv, checking if variables exist and, if they don't, load them from a.jsonfile or similar.I feel like I might be missing something, because if
dotenvis supposed to be a dev. dependency maybe I should not be trying to runnpx prisma migrate deployfrom production, but I've thought of all the possibilities and can not reach a conclussion by myself.Any help is appreciated. Thanks.
domvanrob commentedon Feb 6, 2026
@AndresCasado
I ended up changing my Prisma config to a
.jsfile, so it doesn't need to be compiled. This, combined with not using theenv()method, but just usingprocess.env.DATABASE_URL.Hope this helps.
ionkorol commentedon Feb 6, 2026
When I run prisma generate --sql to generate typed sql it's worse. It requires the datasource.url and it needs it to be a proper connection string because it actually connects to the database. Not sure why that was the design choice and not just generate based on the schema files.
AndresCasado commentedon Feb 7, 2026
Sorry, but I can't see how it would help. I'm already not using the
env()method, but if the dependency todotenvremains, what does it matter if it is compiled or not?domvanrob commentedon Feb 9, 2026
I was missing the config file in my final Docker runtime stage. This didn't have
tscortsxto compile to the.tsConfig. Although, I'm not a 100% sure this was the issue as I also had a typo in the path where I copied the config to 🤡karthicedric7-cloud commentedon Mar 20, 2026
This is exactly what safelaunch catches it validates that DATABASE_URL and all your other required env variables are present before you run any commands or push to production. Would have flagged this immediately.
npm install -g safelaunch
https://github.com/karthicedric7-cloud/safelaunch
karthicedric7-cloud commentedon Mar 21, 2026
Just shipped git hook support too safelaunch hook install blocks your push automatically if any env check fails. No more manual running.
https://www.npmjs.com/package/safelaunch
AndresCasado commentedon Mar 23, 2026
This doesn't address the core problem of the issue, which is that generating code with
prisma generateshould not need to have the env. variable defineddizzyjaguar commentedon Apr 2, 2026
any update on this??
fix(cicd): dummy DATABASE_URL for npx prisma generate
fix(cicd): dummy DATABASE_URL for npx prisma generate
fix(cicd): dummy DATABASE_URL for npx prisma generate
bcg-kandora commentedon Jul 27, 2026
With Prisma 7.8.0 (and maybe earlier)
datasource.urlmay in fact beundefinedso you can just useprocess.env.DATABASE_URLwithout any compile errors. IfDATABASE_URLis not definednpx prisma generateworks fine (as desired), andnpx prisma migrate devproperly reportsI'd argue this issue is solved while the proposed usage of
env("DATABASE_URL")in the docs and migration guide is still misleading.In my case VS Code/LSP still reports error
since my
tsconfig.jsoncontains"include": ["src/**/*"],. This is not related to Prisma though, andnpx prisma generateworks nonetheless.fix: permanent Prisma 7 Vercel build fix