P
Prisma6mo ago
Cyrus

prisma accelerate + custom directory

I need help with prisma acellerate + custom directory the withAccelerate method imported from @prisma/extension-acellerate import from the @prisma/client directory and not the custom directory, which then fails as the module does not exist. How do I change this?
22 Replies
RaphaelEtim
RaphaelEtim6mo ago
Hi @Cyrus Can you please elaborate on how you are using the custom import? A code snippet would help and the error message too.
Cyrus
Cyrus6mo ago
we using a nx monorepo and got the package running our prisma code in packages/utils/prisma in the prisma schema we added output = "../packages/utils/prisma/src/lib/client" our entrypoint file that we import our prisma client from is
import type { Prisma } from '@prisma/client/edge'
import { PrismaClient } from '@prisma/client/edge'
import { withAccelerate } from '@prisma/extension-accelerate'
import { env } from './env'

const log: Prisma.LogLevel[] = env.LOG_LEVEL === 'debug' ? ['query', 'error', 'warn'] : ['error']

export const prisma = new PrismaClient({ log }).$extends(withAccelerate())
import type { Prisma } from '@prisma/client/edge'
import { PrismaClient } from '@prisma/client/edge'
import { withAccelerate } from '@prisma/extension-accelerate'
import { env } from './env'

const log: Prisma.LogLevel[] = env.LOG_LEVEL === 'debug' ? ['query', 'error', 'warn'] : ['error']

export const prisma = new PrismaClient({ log }).$extends(withAccelerate())
as part of moving to the custom directory I changed the import paths to
import type { Prisma } from './client/edge'
import { PrismaClient } from './client/edge'
import { withAccelerate } from '@prisma/extension-accelerate'
import type { Prisma } from './client/edge'
import { PrismaClient } from './client/edge'
import { withAccelerate } from '@prisma/extension-accelerate'
the problem is that last import. We using pnpm by the way so it uses symlinks etc
Cyrus
Cyrus6mo ago
The problem is that inside this directory: node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@prisma/extension-accelerate/dist/cjs/entry.node.d.ts We got this code:
No description
Cyrus
Cyrus6mo ago
look at the part where it says import("@prisma/client/scripts/default-index.js") in line 2 its looking at @prisma/client which would obviously mean /node_modules/@prisma/client which does not exist as we got a default directory @RaphaelEtim @Jan (Prisma) any news?
RaphaelEtim
RaphaelEtim6mo ago
Hi @Cyrus, Thank you for a detailed explanation. Can you also please provide the exact error message that surfaced.
Cyrus
Cyrus6mo ago
No description
Cyrus
Cyrus6mo ago
but the error is obscure. The issue is that it cant find the package that is referenced
Cyrus
Cyrus6mo ago
This issue is related: https://github.com/prisma/prisma/issues/23319 The reason we need a custom directory in the first place is because of nx caching not working with pnpm symlinks (at least thats what it seems like)
GitHub
Error when using multiple prisma clients generated under `@prisma/c...
Bug description We have multiple DBs and multiple prisma clients generated to node_modules/@prisma/client/{db-name} bar/db/prisma/schema.prisma generator client { provider = "prisma-client-js&...
Cyrus
Cyrus6mo ago
This is how the @casl/prisma guys fixed the same issue: https://github.com/stalniy/casl/issues/621 Maybe accelerate can also use a generator?
GitHub
Can't use Prisma package if built into custom directory · Issue #62...
Here's a repro of type errors with Prisma 3.14 (same with 3.0.2) https://codesandbox.io/s/cranky-frog-dy6nfq?file=/src/index.ts No typesafety for conditions with AbilityBuilder and type error w...
RaphaelEtim
RaphaelEtim6mo ago
Thank you for sharing. I have forwarded it to the team and will get back with updates,
Cyrus
Cyrus6mo ago
Thanks, standing by
Nurul
Nurul6mo ago
@Cyrus Would it be possible for you to share a minimal reproduction with us? Maybe you could strip out all other parts of the code and share bare minimum code needed for us to reproduce this. Having a minimal reproduction would allow us to debug and resolve this quickly. Also, here's a hunch reported by our engineering team on what might be causing this issue:
That sounds like they don't have the @prisma/client dependency added to the monorepo project that contains new PrismaClient(...).$extends(withAccelerate()). Even when using a generated client, the @prisma/client dependency still needs to exist. It isn't only used for the generated client; it also contains a number of files by default that make client extensions possible.
Cyrus
Cyrus6mo ago
I am pretty sure I already pointed out the issue, but sure let me do that. I'll do these 3 steps: - bootstrap a t3 app with pnpm https://create.t3.gg - add withAccelerate to prisma https://www.npmjs.com/package/@prisma/extension-accelerate - switch to a custom prisma output directory https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path Will let you know when its done
Cyrus
Cyrus6mo ago
GitHub
GitHub - cyrus-za/prisma-acellerate-issue
Contribute to cyrus-za/prisma-acellerate-issue development by creating an account on GitHub.
Cyrus
Cyrus6mo ago
I am running into a different issue here with typings, but after you able to fix that you should run into the same issue. just to be 100% clear, there's no building issue until the very last commit that changes the custom output directory any update? I ended up reverse-engineering the generated code in node_modules/@prisma/extension-accelerate and creating ts files from that, which I locally maintain. I removed node-fetch as I am running nextjs so fetch is in global namespace. I then went and imported the prisma client directly from my generated output rather than node_modules and it seems to be working. Needless to say, I dont want to maintain that code so I still need a solution where the withAccelerate method gets generated into the custom output directory rather than importing it from the node_modules thing.
Nurul
Nurul6mo ago
Thank you for letting us know about your workaround 🙏 I have shared the repository with our engineering team and are looking into resolving this issue. I'll keep this thread updated.
Cyrus
Cyrus6mo ago
ty What did the engineering team say?
Nurul
Nurul6mo ago
The latest update is that I shared the workaround you shared with us. We are still investigating with the help from your reproduction repository, I'll get back as soon as I have an update.
Cyrus
Cyrus6mo ago
thanks What's the ETA here? I've been waiting 5 months for this issue already...
Nurul
Nurul6mo ago
@Cyrus Apologies for the delay in getting back to you and that you had to reach out to other team member. I'll ensure that I provide timely updates to you in this thread so that our communication and expectations are clear 🙏 If you would like we can move this conversation to our dedicated PDP support channel, as Discord is more focused for community support. We can continue on Discord as well, whatever works best for you. Our teams (ORM and PDP (Accelerate)) are discussing this issue to identify the next steps. I will provide you with an update by this Thursday (16 May). Meanwhile, I believe that your custom workaround is allowing you to continue use Accelerate. Please let us know in case you are facing any other issues. We understand that the workaround is not ideal and you would like to get rid of it as soon as possible. We appreciate your patience and assistance in helping us with this issue.
millsp
millsp6mo ago
Hey @Cyrus 👋🏽 Thanks for sharing this issue and taking the time to work on a reproduction.
I am running into a different issue here with typings, but after you able to fix that you should run into the same issue.
I indeed ran into a type issue when I tried to run pnpm build the first time. It seems Next.js was running tsc on JS files which are not meant to be type checked. I then set "checkJs": false, in tsconfig.json and the error went away. Further down, I went to server/db.ts to find out about the type issues for the custom directory. While we do have autocompletion issues that I will report, types are fully working (at least in your repro). Would you be able to help us with a more complete repro, maybe nx is indeed the root cause of this issue?
look at the part where it says import("@prisma/client/scripts/default-index.js") in line 2 its looking at @prisma/client which would obviously mean /node_modules/@prisma/client which does not exist as we got a default directory
For context, these types are not your generated types, but they are utility types for the extension to work correctly. In my case, with your reproduction, these types do exist because @prisma/client is installed in the root of the monorepo. So if these types aren't found in your nx project, you can try to ensure @prisma/client is installed in the root of your project. tldr; I was not able to reproduce, though I can imagine how this could fail. Could you please provide me with an updated repro? Also happy to jump on a call if that can help.
No description
No description
Cyrus
Cyrus6mo ago
Thanks for the response. I will work on a repro when in the next few days. Just have a deadline this week
Want results from more Discord servers?
Add your server