60

Functions deploy had errors. To continue deploying other features (such as database), run:

firebase deploy --except functions

Error:

Functions did not deploy properly.

Geoff James
  • 3,122
  • 1
  • 17
  • 36
Mario
  • 847
  • 1
  • 8
  • 13
  • I'm having the same problem. With firebase-tools version 3.8.0 and version 3.9.0 – MikeG May 23 '17 at 04:18
  • I just came back to it this morning, and ran `firebase deploy --only functions` and its now working again without me changing anything – MikeG May 23 '17 at 13:02
  • 1
    actually it's worth noting that I did make one small change. Last night, just before I started getting this error, I changed the name of the function. Then this morning I changed the name back again to the original name and it worked fine. Can't be sure if changing the function name caused the error but it's possible – MikeG May 23 '17 at 13:34
  • i think changing the name then changing it back did actually fix it for me – ewizard Feb 15 '18 at 20:57
  • 2
    Ensure that the billing account is active. In my case billing enabled account was suspended due to expired the card. – Deva Jun 09 '21 at 08:41

32 Answers32

70

Try running deploy with --debug. For example: firebase --debug deploy.

In my case the function looked like this:

exports.test = functions.firestore.document('chats').onCreate((snap, context) => {
   ...
});

The debug log contained the following error message:

fieldViolations=[field=event_trigger, description=Expected value chats to match regular expression [^/]+/[^/]+(/[^/]+/[^/]+)*]]

And that's when I realized that chats is not a document but a collection. I changed the path to that of the collection and everything worked fine.

EDIT:

To view more logs you can also try:

firebase functions:log

or

firebase functions:log --only <FUNCTION_NAME>

Link to documentation.

Georgios
  • 4,764
  • 35
  • 48
  • This is helpful, It helped me find the real error. Mine was -- "Change of function trigger type or event provider is not allowed," because I changed from firestore to firebase... I had to manually delete the function via "firebase functions: delete myFunction" – Peege151 Jul 09 '20 at 06:05
  • 5
    This should be the accepted answer since the error is super generic, there are a lot of comments saying "For me it was...". But using --debug tells you exactly what you have wrong – Luis Gurmendez Mar 18 '21 at 01:23
  • to add to this, if you look at the `package.json` in your firebase `functions` directory, the default way that gets put together for a firebase project seems to be mapping `firebase functions:log` to `npm logs` – codeAndStuff Sep 25 '21 at 12:04
  • I've found that running with --debug can sometimes make a failed deploy succeed (if there's nothing with the code and firebase has just got confused) – danday74 Oct 21 '21 at 00:47
  • 1
    Echo what @danday74 and others have said: using `--debug` gives info not provided in the logs (ie. sometimes the logs contain nothing helpful or useful), and it also sometimes fixes a broken deployment. We've had a number of cases where an initial deployment fails, then the function is "dead" for some reason and even deleting & recreating doesn't fix. Deploying with `--debug` always seems to work in these cases ?! – cayleyh Nov 04 '21 at 16:54
22

I had the same issue with Firestore ,my problem was that the path to the document was bad. I had a slash at the beginning and the end of the path to my document like I used to do with Firebase Realtime Database path. Hope it helps someone.

jamesthakid
  • 1,265
  • 10
  • 11
  • Just in addition to this, the mistake for me was that I was constructing a path to a sub-collection without slashes in the document parts. eg. `const triggerPath = RootCollection + '/{documentId}' + SubCollection + '/{subDocumentId}'` instead of: `const triggerPath = RootCollection + '/{documentId}/' + SubCollection + '/{subDocumentId}'` Subtle but deadly! – zippycoder Mar 31 '21 at 04:26
  • I had a slash at the front and an incorrect {id} at the end when the actual value should have been. {ratingId} – Jacob Sherwood Feb 08 '23 at 16:49
11

Just close whatever IDE you're using and then reopen it. Then on node redeploy your functions. This should resolve the issue.

Junia Montana
  • 443
  • 7
  • 11
  • 4
    how did you get to this solution? it worked for me well, but it doesn't make any sense. – sina Jan 07 '20 at 18:10
  • It was long time ago. But, I think it's some sorts of bug. I remember I couldn't find any issue on the index file, all the settings were correct but still I was experiencing the issue. So, I decided to shut down the vsCode and tried redeploying and it worked perfectly fine. Each time I was having this issue, I was repeating this process. – Junia Montana Jan 07 '20 at 18:55
  • This is really weird. I also had to restart VSCode and then the deploying worked. – Michael Baumgärtner Apr 16 '22 at 19:46
9

I got this error as well, I had the problem that a dependency was missing in the package.json file.

By running firebase --debug deploy it returned an error on the user code. firebase functions:log gave then the specifics, that a package was not included.

seveneights
  • 425
  • 5
  • 15
7

I deleted yarn.lock then error goes away. I think package-lock.json and yarn.lock should not exist together.

Roeniss
  • 386
  • 5
  • 16
6

Check your json modules dependencies inside functions folder. There's an specific json package there. If some module you are including in the project and is not there (in json) you probably will have the error mentioned. To install just run:

npm install <module> --save

or

yarn add <module> --save

and then run your deploy again:

firebase deploy --only functions

Mario
  • 847
  • 1
  • 8
  • 13
  • I checked hat each module was installed but i'm still getting this error – MikeG May 23 '17 at 04:21
  • 2
    I had this issue, it's because you're often in the parent dir on firebase so the --save doesn't work, Check your package.json, and look for missing dependencies then `cd` in the functions folders and use the `--save` flag to add missing ones. This fixed this exact issue for me. It's how `firebase init` creates the folder that leads to this issue if you're not focused. – Benjamin Jan 25 '21 at 05:49
  • for me it was `npm install firebase-functions` ...the online docs told me to run `npm install -g firebase-tools` but left me in the dark with installing libraries for specific services – RumbleFish Apr 07 '23 at 00:29
5

In my case firebase deploy failed with the error "Error: Functions did not deploy properly." and no further explanation. I noticed that no functions could be deployed even the ones I didn't touch. So I checked for dependencies and I found that a library was not present in the "package.json".

So I execute this command:

cd functions && rm -rf node_modules && rm package-lock.json && npm install && npm install [specific Librairy not in package.json] && firebase deploy

After that the deployment succeeded and the missing dependency appeared in the package.json

bulgarian-beast
  • 367
  • 3
  • 10
4

Recently Firebase lets you use Functions only if you have the Blaze-Pay as you go plan. So you cannot deploy functions as well, and you will get this same error message without any further clarifications.

SAJJAN K
  • 96
  • 3
2

Mine was about;

"Function deployment failed because the billing account is not available."

So I had pending payment, after paying, it worked as expected.

Enes Karaosman
  • 1,889
  • 20
  • 27
2

I was running into the same generic error message, and ended up running (as mentioned in this question):

firebase --debug deploy --only functions:[functionName]

This revealed the actual issue (my project did not have a default GCP resource location, fix for this described here: Firebase Project Initialization Error: Cloud resource location is not set for this project)

Once I set the GCP resource location, function deployed without issue!

enter image description here

Blundell
  • 75,855
  • 30
  • 208
  • 233
2

In my case, After a long time of searching, I found the reason to be that I had disabled billing for the project for debugging.

It worked fine now after I enabled it in the Google cloud console.

It's really sad how firebase can't show any useful error message to suggest the problem. I found this after many trials.

Abraham
  • 12,140
  • 4
  • 56
  • 92
2

I faced a similar problem, but I was using Typescript.

It was basically targeting a non-supported javascript version (ES2020). I changed the tsconfig.json and it deployed normally

"lib": [
  "es2019",
  "es2020.bigint",
  "es2020.string",
  "es2020.symbol.wellknown"
],
"module": "commonjs",
"target": "es2019"
Celo Reis
  • 37
  • 1
1

After getting the above deploy error, I edited the index.js file and changed the name of the function from "helloWorld" to "heyWorld" and suddenly the firebase deploy command worked.

1

If anyone gets here trying to deploy ssr functions in angular universal with firebase, it is because firebase is not included in your functions.

1.) cd functions

2.) npm i firebase@latest

3.) npm run deploy

4.) cd ..

5.) now when you run ng deploy it should work correctly... The key here is to add firebase, and deploy with npm run deploy first...

Functions did not deploy properly.

Jonathan
  • 3,893
  • 5
  • 46
  • 77
1

try to add this

"runtime": "nodejs12"

in your firebase,json

example :

"functions": {
    "source": ".",
    "ignore": [
      ".firebase/**",
      "**/node_modules/**",
      "**/public/**",
      ".firebaserc",
      "firebase.json",
      "postcss.config.js",
      "README.md",
      "tailwind.config.js"
    ],
    "runtime": "nodejs12"
  }
Super Noob
  • 99
  • 5
1

was with the same error, I ended up solving it by updating package.json

from:

"engines": {
    "node": "12"
 },

to:

"engines": {
    "node": "14"
 },
Gustave Dupre
  • 101
  • 1
  • 4
1

$ in path causes Error: Functions did not deploy properly.

before:

`export const newMessage = functions.firestore.document('chats/${chatId}/messages/${messageId}').onCreate(handleNewMessage())`

after:

`export const newMessage = functions.firestore.document('chats/{chatId}/messages/{messageId}').onCreate(handleNewMessage())`
Gavin Chebor
  • 265
  • 3
  • 5
1

In my case, the location for the Firestore was not correctly set. From the Functions Documentation:

By default, functions run in the us-central1 region.

In my case, Firestore was set up on a different location. You can find this under Project Settings, at Default GCP resource location.

To fix it, simply make the following change:

// Before
functions.firestore.document("...").onCreate(...)

// After
functions.region("asia-east2").firestore.document("...").onCreate(...)
Razvan Fulea
  • 437
  • 4
  • 13
1

Follow the steps below:

  1. Deploy with debug enabled: firebase --debug deploy You will see the error printed in your console. In most cases it is something similar to the line below:

npm install before continuing.\nnpm ERR! \nnpm ERR! \nnpm ERR! Invalid: lock file's body-parser@1.19.0 does not satisfy body-parser@~1.0.1\nnpm ERR!

  1. If the error is similar to "lock file's body-parse" in 1) above: Go to the views directory in your project and edit the dependencies section in your package.json file as below: Change the body-parser version to the latest version shown in the error printed in 1) above. In my case it was from body-parser@~1.0.1 to body-parser@~1.19.0
  2. Run: npm install
  3. Re-deploy with: firebase deploy

This should work.

If you get a 403 error from your hosting URL after re-deploying, your CLI version could be out of date:

  1. Login to you google cloud account and go your the google cloud console.
  2. Delete your Cloud Functions
  3. Update Firebase CLI using: npm install -g firebase-tools
  4. Re-deploy: firebase deploy
Elijah Baraza
  • 291
  • 4
  • 4
  • Simplest Solutions are usually the best one...that and going here - https://github.com/firebase/firebase-functions/issues/795 – Leon Aug 24 '21 at 06:24
0

My firebase couldnt find the modules firebase-functions and firebase-admin on deploy because I wrote them in devDependencies instead of just dependencies. But after it ... I still had an issue. But this solved it for me: https://github.com/nuxt/nuxt.js/issues/2714#issuecomment-423048343.

Just notice node 8 as engine object in your function's folder package.json and add the babel snippet in your nuxt config.

phng
  • 344
  • 3
  • 12
0

I had same problem with Firebase project deployment. Then figure out error and find that some module paths are cause problem. Then i changed the path of that module.

To try redeploying those functions, run: firebase deploy --only functions:api,functions:createScream

To continue deploying other features (such as database), run: firebase deploy --except functions

Error: Functions did not deploy properly.

The error shows that could not find modules.

Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module (../key/your secret key.json) '

Then i changed the path of my secret key that is required for login credentials and put it in different folder. Then run firebase deploy. That work for me.

akshay_sushir
  • 1,483
  • 11
  • 9
0

I had the same problem. The problem came from the fact that I had an index.js file and package.json file in the root folder and, after running the firebase functions init command, also an index.js and package.json in the functions folder. The dependencies are only listed in the package.json file in the root folder, not in the functions folder. I copied the dependencies to the package.json file in the functions folders and everything worked like a charm.

Gijs van Beusekom
  • 305
  • 1
  • 3
  • 9
0

Deleting the build functions folder worked to me

Rodrigo João Bertotti
  • 5,179
  • 2
  • 23
  • 34
0
firebase functions:log

This allowed me to find out the problem in my case: one of the packages was not listed among the dependencies in package.json

  • 1
    This looks like a useful answer but perhaps you could add a little context to explain, using your own experience, what you did to solve the problem. – Graham Asher May 11 '21 at 17:02
0

This worked for me today: Delete Function and Redeploy.

jbryanh
  • 1,193
  • 7
  • 17
0

It happened the same to me but unfortunately I had not any error with --debug.

I then deleted all my deployed functions in the firebase console and

cd functions
rm -rf node_modules
npm install
firebase deploy --only functions

and it worked like magic.

mastodilu
  • 119
  • 1
  • 9
0

I got the same error

Functions were working in emulator, but couldn't be deployed. When I deployed functions using debug, I got no more specific info.

Then I found out, that my IDE accidentally imported lib (that I wasn't even using) from parent folder where is my Svelte project located.

Removing that import fixed my error, obviously.

Hejtmus
  • 101
  • 1
  • 8
0

I deleted the recently added 3rd party library (from package/package-lock.json as well). And checked the name of the function to not be a duplicate. This worked for me.

Alex Balas
  • 99
  • 1
  • 1
0

If u are using SSR you need declare your node version In my case my node version is 14 and firebase was deploying with 10.0 I set this config on angular.json

        "functionsNodeVersion": 14
        "serve-ssr": {
      "builder": "@nguniversal/builders:ssr-dev-server",
      "options": {
        "browserTarget": "Rioja-web:build",
        "serverTarget": "Rioja-web:server"
      },
      "configurations": {
        "production": {
          "browserTarget": "Rioja-web:build:production",
          "serverTarget": "Rioja-web:server:production"
        }
      }
    },
    "prerender": {
      "builder": "@nguniversal/builders:prerender",
      "options": {
        "browserTarget": "Rioja-web:build:production",
        "serverTarget": "Rioja-web:server:production",
        "routes": [
          "/"
        ]
      },
      "configurations": {
        "production": {}
      }
    },
    "deploy": {
      "builder": "@angular/fire:deploy",
      "options": {
        "ssr": true,
        "functionsNodeVersion": 14
      }
    }
  }
Mike
  • 1
0

I had the same problem. updating node engine to 16 in package.json solved the issue.

My nodejs local version was 16.

{
...
"engines": {
    "node": "16"
 },
 "main": "lib/index.js",
 "dependencies": { ... }

}
bouraine
  • 61
  • 3
  • it give the following error `Error: package.json in functions directory has an engines field which is unsupported. Valid choices are: {"node": "10"}, {"node":"12"}, and {"node":"14"}.` – ABDERRAHMANE OUALI Jan 17 '22 at 09:48
0

If everything mentionned up there is not working for you then subscribe to the blaze plan

https://console.firebase.google.com/u/0/project/_/overview?purchaseBillingPlan=metered
Pascal Nitcheu
  • 667
  • 7
  • 8
0

In case you are trying to deploy a database trigger, make sure to explicit the database's instance if you have more than one. By the Functions console page, you can see more details about the deploy error. In my case it was:

Database instance 'projects/_/instances/<DEFAULT_DATABASE_NAME>/...' has been disabled

To explicit the database instance:

.database.instance(<NEW_DATABASE_NAME>).ref
Fabrizio Billeci
  • 572
  • 2
  • 10
  • 18