Why are client files generated in node_modules and what does that mean for production builds?
In Prisma 1, generated files were kept within source control. This makes sense to me as it meant edits to the schemas and generated files were kept together, and at any given moment I could see locally exactly what code is running on our production servers.
In Prisma >=2 though, client files are in
node_modules
so they are not in our repositories. Obviously this makes our repos much lighter which is great, but presumably every time we make a database change, we need to not only deploy it, but then each production server needs to regenerate its client files?
Now if the schema files are in source control and the version of prisma/client
is pinned in package.json
then the output of the file generate should be the same every time, but the fact that I can't guarantee to my boss exactly what code we have running in production, the commit hash for that code, and the test results for that commit hash makes me very uneasy.
So I guess the main question is am I thinking too much about this and I should just need to add a line to our build scripts to get each app server to rebuild the client files every deploy? Or is there something I've missed?4 Replies
Funnily enough I've just run into this exact issue. I have a self-referential relationship on a table and if I change the name of one end of the relation, when I regenerate the files the ends of the relationship swap over. ARRRRRRRRGGHHHH
So I can now be in a position where my two app servers are accessing data in different ways
Prisma 1 wasn't perfect but at least it was consistent
Hey @Moray 👋
You can generate client files outside of node_modules as well.
https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path
If you use the default location of generating inside node_modules, then you need to ensure that
npx prisma generate
is a part of your build script to ensure that your production build is in sync with your schema file and any changes you make are correctly reflected.Generating Prisma Client | Prisma Documentation
This page explains how to generate Prisma Client. It also provides additional context on the generated client, typical workflows and Node.js configuration.
Phew, thanks!
No worries! Happy to help! 🙂