I have an app running on firebase functions as back-end API with relational database (MySQL) on other server. I use Prisma as ORM.
Every time when my model changes, Prisma needs to generate proxy classes npx prisma generate.
All works great from local dev environment, but when deploying to production, firebase remembers old model.
As I understand, npx prisma generate creates files in node_modules which is not re-deployed by default. The only way I found to fix this, is to change the minor version of Prisma in package.json and than redeploying.
My patch-fix is to do this version change every time the model changes, but it definitely shouldn't be working like this.
Can I force firebase to update its node_modules content?
You may have a file already named firebase.json in the directory just above your functions. In that file there is a place for predeploy steps. Commonly it has a lint and a build script already. Something like this
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
]
}
So in your package.json add a generate script maybe "p-generate"
... etc,
"deploy": "firebase deploy --only functions",
"p-generate": "prisma generate",
...etc
Then update your predeploy to include this
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run p-generate",
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
]
}
And would put it first etc, so that lint and build use latest.
At least this is my first thought, I am also thinking to back a cloud function with postgres and prisma so will circle back if I encounter bumps, but seems like that would work well. And if you are deploying in automated environment similarly add this generate step right after the npm install step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With