P
Prisma•6mo ago
jacob

Multiple prisma schemas with custom output directory throws errors on generate

Hi. This is my codebase structure: - prisma/schema.prisma (I have main config like db connection here) - prisma/schema directory which contains multiple .prisma files - i have output folder for prisma client in prisma/client My problem is that the initial prisma generate works but once it is generated I cannot run prisma generate again because it marks everything as duplicately defined. Is there a way to fix this?
9 Replies
Prisma AI Help
Prisma AI Help•6mo ago
You opted for speed from this bot. Let's conjure up an answer right now! Your issue is a common challenge when using multiple Prisma schema files and a custom output directory. The main problem is that when you run prisma generate, Prisma merges all .prisma files (if you use a setup like schema.prisma plus additional files in a subdirectory), which can lead to duplicate model or generator definitions if the files are not managed carefully. Key points and solutions: 1. Duplicate Definitions: If you have multiple .prisma files that each define generators, datasources, or models with the same names, Prisma will throw errors about duplicate definitions on subsequent generates. This is expected behavior if the files are all included together and not properly separated or composed. 2. Recommended Structure: The typical approach for multiple schemas is to keep each schema in its own directory, with its own schema.prisma and output directory. For example:
prisma/
db1/
schema.prisma
db2/
schema.prisma

prisma/
db1/
schema.prisma
db2/
schema.prisma

Then, generate each client separately:
npx prisma generate --schema=prisma/db1/schema.prisma
npx prisma generate --schema=prisma/db2/schema.prisma

npx prisma generate --schema=prisma/db1/schema.prisma
npx prisma generate --schema=prisma/db2/schema.prisma

This avoids conflicts and duplicate definitions, as each schema is processed in isolation Multiple Connections / Databases / Datasources. 3. Custom Output Directory: If you use a shared output directory (e.g., prisma/client), ensure only one schema writes there, or you risk overwriting or conflicting files. Each schema should have its own output directory to prevent this. 4. Workarounds: If you want to compose schemas, you must ensure that only one generator and datasource block exists in the final composed schema, and that model names do not conflict. Otherwise, Prisma will error on generate Abnormal behavior of schema.prisma outside the main folder. Summary:
To fix your issue, separate your schemas into dif ferent directories, each with its own output, and run generate for each schema individually. Avoid merging multiple generator or datasource blocks in a single generate run. If you need more advanced schema composition, Prisma currently does not natively support this without manual schema management.
jacob
jacobOP•6mo ago
This does not solve my issue. I still need to have one file that will have the config, either in root prisma folder or under schema folder and other schemas inside schema folder.
Prisma AI Help
Prisma AI Help•6mo ago
šŸ¤” Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
jacob
jacobOP•6mo ago
I cannot share more of the code since it is under NDA but I had to create symlinks for @prisma/client beecause it was getting called for no reason even though I use my generated prisma client references everywhere.
# Reinstall dependencies to ensure Prisma engines are available
bun install

# Generate Prisma Client
bun prisma generate --schema=./prisma/schema/

# Replace @prisma/client with our generated client to avoid conflicts
rm -rf node_modules/@prisma/client
ln -sf ../../generated/prisma-client node_modules/@prisma/client

bun prisma migrate deploy --schema=./prisma/schema/
# Reinstall dependencies to ensure Prisma engines are available
bun install

# Generate Prisma Client
bun prisma generate --schema=./prisma/schema/

# Replace @prisma/client with our generated client to avoid conflicts
rm -rf node_modules/@prisma/client
ln -sf ../../generated/prisma-client node_modules/@prisma/client

bun prisma migrate deploy --schema=./prisma/schema/
This is the error I have been getting.
(function (entry, fetcher)
^
SyntaxError: Export named 'DisputeStatus' not found in module '/var/www/html/generated/prisma-client/index.js'.
at loadAndEvaluateModule (1:11)
Bun v1.2.17 (Linux arm64)
(function (entry, fetcher)
^
SyntaxError: Export named 'DisputeStatus' not found in module '/var/www/html/generated/prisma-client/index.js'.
at loadAndEvaluateModule (1:11)
Bun v1.2.17 (Linux arm64)
I cannot provide any more details at the moment, I do not know if this is a Prisma bug or an issue on my end. My current setup is:
prisma
ā”œā”€ā”€ migrations
│ └── 00010101000000_init
│ └── migration.sql
└── schema
ā”œā”€ā”€ account.prisma
ā”œā”€ā”€ badge.prisma
ā”œā”€ā”€ calendar.prisma
ā”œā”€ā”€ category.prisma
ā”œā”€ā”€ counterparty.prisma
ā”œā”€ā”€ custom-column.prisma
ā”œā”€ā”€ dispute.prisma
ā”œā”€ā”€ document.prisma
ā”œā”€ā”€ expense.prisma
ā”œā”€ā”€ gocardless.prisma
ā”œā”€ā”€ invoice-upload.prisma
ā”œā”€ā”€ mail-service.prisma
ā”œā”€ā”€ organization-user.prisma
ā”œā”€ā”€ organization.prisma
ā”œā”€ā”€ prediction.prisma
ā”œā”€ā”€ product.prisma
ā”œā”€ā”€ rate.prisma
ā”œā”€ā”€ report.prisma
ā”œā”€ā”€ salary.prisma
ā”œā”€ā”€ schema.prisma
ā”œā”€ā”€ system.prisma
ā”œā”€ā”€ transaction.prisma
ā”œā”€ā”€ user.prisma
└── vacation.prisma

4 directories, 25 files
prisma
ā”œā”€ā”€ migrations
│ └── 00010101000000_init
│ └── migration.sql
└── schema
ā”œā”€ā”€ account.prisma
ā”œā”€ā”€ badge.prisma
ā”œā”€ā”€ calendar.prisma
ā”œā”€ā”€ category.prisma
ā”œā”€ā”€ counterparty.prisma
ā”œā”€ā”€ custom-column.prisma
ā”œā”€ā”€ dispute.prisma
ā”œā”€ā”€ document.prisma
ā”œā”€ā”€ expense.prisma
ā”œā”€ā”€ gocardless.prisma
ā”œā”€ā”€ invoice-upload.prisma
ā”œā”€ā”€ mail-service.prisma
ā”œā”€ā”€ organization-user.prisma
ā”œā”€ā”€ organization.prisma
ā”œā”€ā”€ prediction.prisma
ā”œā”€ā”€ product.prisma
ā”œā”€ā”€ rate.prisma
ā”œā”€ā”€ report.prisma
ā”œā”€ā”€ salary.prisma
ā”œā”€ā”€ schema.prisma
ā”œā”€ā”€ system.prisma
ā”œā”€ā”€ transaction.prisma
ā”œā”€ā”€ user.prisma
└── vacation.prisma

4 directories, 25 files
package.json
"prisma": {
"schema": "./prisma/schema/"
}
"prisma": {
"schema": "./prisma/schema/"
}
Client output is set to following: output = "../../generated/prisma-client" And this script is being run at the end of Dockerfile
Sheik Mostafizur
Sheik Mostafizur•6mo ago
@jacob Is you multiple .prisma files working?
jacob
jacobOP•6mo ago
It is locally, but I had to spend a lot of time making it work in Docker
Sheik Mostafizur
Sheik Mostafizur•6mo ago
I am not setting up it can you help me?
jacob
jacobOP•6mo ago
Create your own thread
Nurul
Nurul•6mo ago
Can you check if you are getting the error in latest prisma version - 6.11.0 as well?

Did you find this page helpful?