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
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?
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:
cd functions
(in this case replace the ‘functions’ name for your project)npm install
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.
functions
npx tsc --watch
And try serving and deploying the project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With