Sometimes when you're deploying a monorepo to Cloud Functions for Firebase, you'll get the following error:
Error: There was an error reading functions/package.json:
functions/lib/index.js does not exist, can't deploy Cloud Functions
In some cases, that's happening because you're importing external types and Typescript is adding them to the compiled lib
folder. Therefore, Firebase isn't able to find your functions because the default path is wrong.
Because Firebase uses the main
field from your functions/package.json
file, you just have to update it with the correct compiled path:
{
"main": "lib/functions/src/index.js"
}
Top comments (6)
Awesome! This must be the fourth or fifth time I have been all like "WTF" and needed this fix, but each time separated by years so I needed to go searching for it. For me it comes from a love of strong typing and wanting to share models between the front end and back end code. It fails to deploy and I remember that this practice changes my compiled functions file structure, then go searching around the firebase config files trying to fix it. For some reason I always forget that it comes from package.json even though the error seems to indicate that. I guess more causes than just deploying a monorepo, but same basic fix.
how you do it?
Thank you! I still had the old index file on my local machine. So used so much time figuring out why it failed on deploy. Your post explained it perfectly, and made it possible for me to fix my problem! Thank you for that!
This did not work for me.
dev.to/help_me_iam_verking/functio...
Thanks for the information! It was driving me nuts why it didn't work anymore, after I did some very minor type changes :D