When I init Prisma from the projects root, prisma ...
# orm-help
m
When I init Prisma from the projects root, prisma seems to completely ignore the top-level
prisma
folder and tries to take both the
schema.prisma/.env
files from the deeply nested assets bundles from the infrastructure deployment outputs. Which does not even exist in those locations! Prisma is trying to load this path, which does not exist:
/Users/hindley/Documents/project/aws/cdk.out/asset.352d16b78797811d23876d149c74340d4b5ae90245ec70aee0bc6d643d46fd1d/prisma/.env
There is however a directory that looks somewhat like that but not quite:
/Users/hindley/Documents/project/aws/cdk.out/asset.352d16b78797811d23876d149c74340d4b5ae90245ec70aee0bc6d643d46fd1d/node_modules/.prisma/
I don’t even know how it’s finding the paths, not only that, the prisma determined location is missing the files it’s trying to load. The
aws
folder is excluded from tsconfig, is built separately and it’s also it’s own package with it’s own dependencies. There is nothing imported from there from the root-level entrypoint, this is triggered by simply importing the prisma client from any root-level file. I found this out by setting a breakpoint in https://github.com/prisma/prisma/blob/ba74c81fdbc9e6405946fdc6f9d42d103d008dc2/packages/client/src/runtime/getPrismaClient.ts#L300. envPath.schemaEnvPath is pointing to the alphabetically sorted most recent asset build. I suspect prisma is doing some deep tree traversal to find schema.prisma/.env files instead of checking things in the order that docs link below state. This is not consistent with the docs at https://www.prisma.io/docs/guides/development-environment/environment-variables#env-file-locations. It should load the
prisma/.env
files and though not specific, I would understand that the
prisma/schema.prisma
file should be used too, and not the first one encountered in deeply nested directories. Here is a basic repo: https://github.com/MichaelHindley/prisma-env-dbg
Note that the repo is not exactly the same dir structure as the real project, but the issue seems to be having a schema.prisma file anywhere alphabetically before the prisma/schema.prisma file, regardless of how deep in a directory structure it is. I’ve updated the readme in repo with this finding. I don’t think this behaviour of alphabetically deeply parsing the project tree and using the first schema.prisma file is a sound behaviour. May I suggest following the same as the .env files.
r
@MichaelHindley 👋 How are you bundling Prisma at the moment?
Also it would be great if you could create an issue regarding this behaviour so that we can look into this.
@MichaelHindley Let me know if you can create one or else I’ll do it 🙂
m
sorry hectic times, it’s on my todo but all info I have is already here and in the repro to be fair!