DEV Community

Will Ceolin
Will Ceolin

Posted on • Updated on

functions/lib/index.js does not exist, can't deploy Cloud Functions

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
Enter fullscreen mode Exit fullscreen mode

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"
}
Enter fullscreen mode Exit fullscreen mode

Follow me on Twitter

Discussion (5)

Collapse
methodician profile image
Jacob Johnston

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.

Collapse
ariel profile image
MNSV~スロー

how you do it?

Collapse
help_me_iam_verking profile image
makinggainz

This did not work for me.

Collapse
help_me_iam_verking profile image
makinggainz
Collapse
dondozone profile image
DonDozone

Thanks for the information! It was driving me nuts why it didn't work anymore, after I did some very minor type changes :D