prisma: Prisma client cannot find datamodel path ("schema.prisma")
Bug 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 18 (6 by maintainers)
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
Hey everyone, just a heads up that this has been fixed and is available in
@prisma/client@dev
if you want to try it out. Please let us know if you find anything unexpected. Thanks!Workaround:
Hi @TheVoid-0 !
Could you create a new issue? The template will help fill out what we need to attempt a reproduction.
Your config2.dirname is pointing to node_modules client, and on your schema.prisma you are creating the client on the same dir than the schema is, comment the output line for prisma to create client on node_modules