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 (8)
Hey, I've been trying to debug my problem for like the past 3 hours, and your simple post saved me.
Like most Firebase projects, my project is structured like this:
shared-type-1.ts
has TypeScript types that are used in both the/src
and/functions
. So I'm importingshared-type-1.ts
from/functions/index.ts
. Because of this, when the/functions
folder builds and outputs the result in/lib
, it outputs it like this:As you can see, the transpiled
index.html
moved to a different folder within/lib
, so I had to update themain
entry in thepackage.json
as you suggested.Thanks.
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!
Thank you !
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