P
Prisma3w ago
Fraps

Using Prisma inside firebase functions

Hey guys, I have a backend that runs mostly on Firebase/Firestore functions. However, we started migrating some tables to a PostgreSQL DB and I'm trying to use Prisma on Firebase. Connecting locally and deploying are already figured out by using a VPC + pg-pool. The issue is that when deploying the Firebase functions my code can't find the client library that is being generated. My package.json "scripts": { "build": "tsc", "generate-prisma": "npx prisma generate --sql", "deploy": "npm run generate-prisma && firebase deploy --only functions --force", "deploy:rules": "firebase deploy --only firestore:rules", }, My firebase predeploy: "functions": { "predeploy": [ "echo \"$DATABASE_URL\" && npm --prefix \"$RESOURCE_DIR\" run generate-prisma", "npm --prefix \"$RESOURCE_DIR\" run build", "npm --prefix \"$RESOURCE_DIR\" install --production" ], "source": "functions" }, Error that I'm getting during the deployment step: updating Node.js 20 (1st Gen) function ***... step Function failed on loading user code. This is likely due to a bug in the user code. Error message: Provided module can't be loaded. Did you list all required modules in the package.json dependencies? Detailed stack trace: Error: Cannot find module '.prisma/client/sql' Require stack: - /workspace/node_modules/@prisma/client/sql.js - /workspace/lib/slackBots/aua-daily-update.js - /workspace/lib/index.js - /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/loader.js - /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/main.js at Module._resolveFilename (node:internal/modules/cjs/loader:1225:15) Could not load the function, shutting down.. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation. Has anyone gone through this before?
3 Replies
Prisma AI Help
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Nurul
Nurul3w ago
GitHub
ecosystem-tests/platforms-serverless/firebase-functions at dev · pr...
🥼🧬🧪🔬🧫🦠 - Continuously tests Prisma Client with various operating systems, frameworks, platforms, databases and more. - prisma/ecosystem-tests
Fraps
FrapsOP3w ago
Thanks @Nurul (Prisma), that helped a lot. I didn't know about this ecosystem-tests, that's great Hey, just adding to the topic if anyone finds this post later. Everytime you deploy a firebase function, each function will run it's own npm install. So in order for the client library to be created for each function and in my case the SQL scripts for the new typescript feature, I added this line to scripts under package.json "postinstall": "npx prisma generate --sql --schema=prisma/schema.prisma"

Did you find this page helpful?