Why do I need to disable cache for prisma generate on turborepo?
I don't get it. Doesn't prisma generate rely only in on the prisma schema? If yes, this should be cached in my opinion. Am I missing anything?
3 Replies
You opted for speed from this bot. Let's conjure up an answer right now!
You’re right that, in theory, prisma generate only needs the Prisma schema and should be cacheable. However, in practice, there are issues with caching in monorepo setups like Turborepo, especially when using package managers like pnpm.
The main reason to disable cache for db:generate (which runs prisma generate) in Turborepo is to avoid problems where the generated Prisma Client becomes out of sync with your schema or is missing entirely. This happens because:
- Turborepo’s caching can skip running db:generate if it thinks nothing has changed, but subtle changes (like schema updates or dependency changes) might not always be detected, leading to stale or missing generated clients.
- Package managers like pnpm use side effects caching, which can prevent postinstall hooks (that generate the client) from running as expected, especially when node_modules is restored from cache. This can result in the Prisma Client not being generated at all, or being out of date, unless you explicitly disable cache for db:generate tasks.
- The Prisma team and community recommend setting "cache": false for db:generate in turbo.json to ensure the client is always generated fresh and up-to-date, avoiding hard-to-debug errors in development and CI/CD pipelines. This is a widely used workaround until a more robust solution is available How to use Prisma ORM with Turborepo, GitHub Issue #6603.
So, while caching seems logical, the current ecosystem limitations make it safer to disable cache for db:generate to ensure reliability.
I really dislike this is the reality
✅ Great, thanks for letting us know that this solved your question!