Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot deploy firebase cloud functions, because functions/lib/index.js does not exist

I think there is a bug in firebase cloud functions setup.

I did:

npm install -g firebase-tools

firebase init functions

I have configured it for typescript, everything installed, yet I cannot deploy the functions because I am getting this error message:

Error: There was an error reading functions/package.json:

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

enter image description here

I know that it does not exist - there is no lib folder at all, but what can I do to run the functions?

Why I can't run functions, if I done everything that needed to be done?

like image 831
Ripas55 Avatar asked Oct 15 '25 06:10

Ripas55


2 Answers

I understand you might be following the instructions from the Getting started guide or the Use Typescript for Cloud Functions one, during this section the wizard helps you choose Typescript as your language to write Functions. Please be sure the language and its dependencies are correctly installed. And in this last guide for the Using an existing Typescript project, it asks you to edit the package.json to add a bash script to build your typescript project:

{
   "name": "functions",
   "scripts": {
     "build": "npm run lint && tsc"
   }
 ...

and the firebase.json to add a predeploy hook to run the build script:

 {
   "functions": {
     "predeploy": "npm --prefix functions run build",
   }
 }

but in this case, you need to check if this configuration was made during the installation.

You can check this answer where the user used sudo npm install typescript to install them, and as Doug mentions try to install it only in your project, not globally; and it must be defined in your package.json as well.

Another example that fixed a similar issue where:

  • The user removed everything related to Firebase Functions
  • Entered in the project directory using cd functions (in this case replace the ‘functions’ name for your project)
  • Ran npm install
  • Running again firebase init

Let me know if you were able to solve this problem to further assist you, trying to add more information as steps and documentation followed and the logs.

like image 164
Alex Avatar answered Oct 17 '25 19:10

Alex


  • Open a terminal and cd to functions
  • Then run npx tsc --watch

And try serving and deploying the project

like image 20
Abraham Avatar answered Oct 17 '25 21:10

Abraham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!