Firebase deployment

I have a question so we have T3 application and we want to deploy it to Firebase we are currently running firebase deploy command but the deployed website is not able to use any kind of backend or db. When we run firebase deploy it jusr runs and creates a SSR function and the website is being deployed but when we actually make any kind of TRPC call like normal hello world example is not working in firebase deployment. We don't have a seperate functions folder in our project we have strictly followed folder structure of T3 docs so there is a src/server in which there are tRPC routes defined. I also noticed one more thing whenever I try to access any DB related route in the logs of SSR function which Google created during deployment it says Prisma Client failed to initialise please run prisma generate. I couldn't find any working example or tutorial about deployment of T3 stack with firebase.
12 Replies
Alejo
Alejo•2y ago
Do you have any detailed errors? Did you double-check your environment variables?
NotMe
NotMe•2y ago
Yeah so here are some screen shots which might help
NotMe
NotMe•2y ago
This is my project structure
NotMe
NotMe•2y ago
This is the firebase config
NotMe
NotMe•2y ago
When I run firebase deploy it created a SSR function in google cloud and there I can see these env variables
NotMe
NotMe•2y ago
This is the log of the cloud function when I try to access TRPC or Prisma related routes
NotMe
NotMe•2y ago
Do you know what I am doing wrong here?
Alejo
Alejo•2y ago
thonkku you tried deleting / removing your .env file from the deployment? Seems like it may be overriding whatever you have set in DATABASE_URL on cloud functions (Sorry for the late reply, busy day yesterday 😅 )
Alejo
Alejo•2y ago
If removing/renaming it before deploys works, then you may want to look into adding it to the ignore field in the firebase.json file, I think these are the right docs https://firebase.google.com/docs/hosting/full-config#ignore, may just need to do it inside "functions" rather than "hosting"
NotMe
NotMe•2y ago
Okay so today I remove prisma from code and just ran firebase deploy and i see that normal trpc routes are working fine it's just that prisma error whenever I include prisma in trpc context it gives that error so year on cloud function prisma is not getting deployed i found this thread people trying to deploy prisma on cloud function but don't know how i can use their solution in my project like they refer to Google cf code base of prisma but there are some shell script and all i didn't understood well Here is the discussion link i am talking about they were facing same issue https://github.com/prisma/prisma/discussions/2106
GitHub
Deploying to a google cloud function with typescript · prisma prism...
Hello, I'm looking for some help dealing with an issue when deploying a typescript apollo server using the new prisma client to a google cloud function. For some reason, prisma generate isn'...
NotMe
NotMe•2y ago
I found the root cause and solution: So basically in my project structure I had a prisma folder and inside that schema.prisma file and when I ran firebase deploy the schema.prisma file was not getting uploaded to firebase function and hence my post install script of prisma generate was failing so the work around here is to include this in firebase.json
"predeploy":[ "cp prisma/schema.prisma .firebase/${YOUR PROJECT NAME}/functions/schema.prisma" ]
"predeploy":[ "cp prisma/schema.prisma .firebase/${YOUR PROJECT NAME}/functions/schema.prisma" ]
This copies schema file and puts it into functions folder note to replace your project name before using this. After this you can use this script in package.json:
"postinstall": "npx prisma generate --schema=schema.prisma",
"postinstall": "npx prisma generate --schema=schema.prisma",
This will run npx prisma generate after deployment and we are also mentioning where our prisma file location is I hope this saves hours of searching
Alejo
Alejo•2y ago
Oooh, interesting lynNote
Want results from more Discord servers?
Add your server