P
Prisma3w ago
GMS

CI cache?

I run tsc check and a custom script to seed data in a GHA. They break if I dont have prisma generate, which i run with dotenv -e .env.local -- pnpm prisma generate --no-hints && dotenv -e .env.local -- pnpm exec prisma generate --sql --no-hints Question is: what do I need to cache here? My node_modules is already cached, so do I need to run this everytime? Thanks
6 Replies
Prisma AI Help
Skipping coffee for instant knowledge! Let's brew that AI answer now. If you are caching your node_modules in CI, you might expect that running prisma generate is not always necessary. However, in practice, you should still run prisma generate on every CI run, even with a cached node_modules. Here’s why: - The generated Prisma Client code (in .prisma/client) is not always reliably restored from node_modules cache, especially with package managers like pnpm or in environments like Vercel, due to how postinstall hooks and side effects caching work. This can result in missing or outdated generated client code, causing your TypeScript checks and seed scripts to fail. This is a known issue and the recommended solution is to always run prisma generate after restoring node_modules in CI, regardless of caching strategy Run @prisma/client postinstall on prisma generate, Prisma Client isn't generated on deploying to Vercel. - Caching node_modules does not guarantee that the generated client is present or up-to-date, especially if the schema or dependencies have changed, or if the cache was created before the last generate. - There are also edge cases with monorepos, pnpm, and CI cache where the generated client is not restored as expected, so running prisma generate is the only reliable way to ensure the client is present and correct Why do I need to run npx prisma generate every time I add/remove an npm package?. In summary:
You should continue to run your prisma generate commands on every CI run, even if node_modules is cached. There is no need to cache the generated client separately; just ensure you always generate it after restoring node_modules. If you want to optimize further, you could cache the .prisma directory, but this is not officially documented or recommended, and may not be reliable across all environments Regarding the conditions for downloading the engine folder and below with prisma generate.
GMS
GMSOP3w ago
Do you have an example of caching the .prisma folder?
Prisma AI Help
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul2w ago
You should ideally run prisma generate on every CI run to make sure that Prisma Client is in sync with your schema.prisma file.
GMS
GMSOP2w ago
But as long they match it is fine, correct? Thinking here in caching the folder and using the md5 schema.prisma as cache key
Nurul
Nurul2w ago
Yep, if they match then it's fine

Did you find this page helpful?