3

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?

Ripas55
  • 423
  • 1
  • 6
  • 20
  • Can you show us any imports you have in functions/src/index.ts, to eliminate this being a faulty import problem? – JeremyW Mar 05 '22 at 19:37
  • Hey, can you please share feedback on my answer to know if further assistance is needed? – Alex Mar 10 '22 at 17:47
  • @Alex no, i'm just getting `functions/lib/index.js does not exist, can't deploy Cloud Functions` – Ripas55 Mar 13 '22 at 19:35
  • It would be very useful for the community if you could please provide any feedback on my answer and comment. Thanks! – Alex Mar 25 '22 at 15:43

2 Answers2

0

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.

Alex
  • 778
  • 1
  • 15
  • Could you please try to run the following command: `npm run serve`. That will create the `/lib/` directory and the `/lib/index.js` file that you need to run your application. You can find this step at the bottom of the project structure gray box in the [documentation](https://firebase.google.com/docs/functions/typescript#initializing_a_new_project_with_typescript). – Alex Mar 14 '22 at 21:11
0
  • Open a terminal and cd to functions
  • Then run npx tsc --watch

And try serving and deploying the project

Abraham
  • 12,140
  • 4
  • 56
  • 92