Prisma client cannot find datamodel path ("schema.prisma")
See original GitHub issueBug description
In a monorepo environment, Prisma generates into the prisma
folder at service root, but when the PrismaClient
instance is created, it tries to read the schema file in random subdirectories.
That happened after upgrading Prisma to 3.x
.
How to reproduce
Here is a repo with an example of project configuration:
https://github.com/0x77dev/prisma-datamodel-path
To reproduce:
yarn install
yarn reproduce
Expected behavior
Schema to be accessed at join(process.cwd(), 'prisma', 'schema.prisma')
.
Prisma information
Schema:
generator client {
provider = "prisma-client-js"
output = "."
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid()) @db.Uuid
}
PrismaClient
export const get = async (): Promise<PrismaClient> => {
const { dbURL } = init()
const { PrismaClient } = await import(join(process.cwd(), 'prisma'))
const prisma = new PrismaClient({
datasources: { db: { url: dbURL } },
log:
process.env.NODE_ENV === 'production' ? [] : ['query', 'info', 'warn'],
rejectOnNotFound,
})
await prisma.$connect()
return prisma
}
Environment & setup
- OS: Ubuntu (docker image
ubuntu:latest
) (Linux aef42a236834 5.10.47-linuxkit #1 SMP Sat Jul 3 21:51:47 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
) or macOS Montereyv12.0.1
(Darwin 3c7d0a05571a.lan 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64
) - Database:
PostgreSQL 12
- Node.js version:
v16.13.0
Prisma Version
prisma : 3.5.0
@prisma/client : 3.5.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 78a5df6def6943431f4c022e1428dbc3e833cf8e
Studio : 0.439.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:18 (6 by maintainers)
Top Results From Across the Web
Prisma schema (Reference)
prisma generate : Reads all above mentioned information from the Prisma schema to generate the correct data source client code (e.g. Prisma Client)....
Read more >Data model (Reference) - Prisma
Learn about the concepts for building your data model with Prisma: Models, scalar types, enums, attributes, functions, IDs, default values and more.
Read more >Prisma schema API (Reference)
API reference documentation for the Prisma Schema Language (PSL). ... output, No, String (file path), Determines the location for the generated client, ...
Read more >Prisma Client API (Reference)
findFirstOrThrow retrieves the first record in a list in the same way as findFirst . However, if the query does not find a...
Read more >Generating the client (Concepts) - Prisma
Important: You need to re-run the prisma generate command after every change that's made to your Prisma schema to update the generated Prisma...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If im not wrong you can add the schema.prisma path to your packaje.json, as “prisma”: {“schema”: “your/parth/schema.prisma”}, hope that works for you.
It is not possible in our case, we don’t want to generate prisma in node modules