Error: Functions did not deploy properly

FirebaseGoogle Cloud-Functions

Firebase Problem Overview


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

firebase deploy --except functions

Error:

>Functions did not deploy properly.

Firebase Solutions


Solution 1 - Firebase

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.

Solution 2 - Firebase

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.

Solution 3 - Firebase

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

Solution 4 - Firebase

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.

Solution 5 - Firebase

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

Solution 6 - Firebase

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

Solution 7 - Firebase

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] && npm fund && firebase deploy

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

Solution 8 - Firebase

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.

Solution 9 - Firebase

Mine was about;

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

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

Solution 10 - Firebase

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: https://stackoverflow.com/questions/58579042/firebase-project-initialization-error-cloud-resource-location-is-not-set-for-th)

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

enter image description here

Solution 11 - Firebase

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.

Solution 12 - Firebase

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"

Solution 13 - Firebase

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.

Solution 14 - Firebase

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.

Solution 15 - Firebase

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"
  }

Solution 16 - Firebase

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

from:

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

to:

"engines": {
    "node": "14"
 },

Solution 17 - Firebase

$ 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())`

Solution 18 - Firebase

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(...)

Solution 19 - Firebase

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 [email protected] 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

Solution 20 - Firebase

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.

Solution 21 - Firebase

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.

Solution 22 - Firebase

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.

Solution 23 - Firebase

Deleting the build functions folder worked to me

Solution 24 - Firebase

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

Solution 25 - Firebase

This worked for me today: Delete Function and Redeploy.

Solution 26 - Firebase

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.

Solution 27 - Firebase

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.

Solution 28 - Firebase

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.

Solution 29 - Firebase

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
      }
    }
  }

Solution 30 - Firebase

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": { ... }

}

Solution 31 - Firebase

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

Solution 32 - Firebase

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//...' has been disabled

To explicit the database instance:

.database.instance(<NEW_DATABASE_NAME>).ref

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarioView Question on Stackoverflow
Solution 1 - FirebaseGeorgiosView Answer on Stackoverflow
Solution 2 - FirebasejamesthakidView Answer on Stackoverflow
Solution 3 - FirebaseJunia MontanaView Answer on Stackoverflow
Solution 4 - FirebaseseveneightsView Answer on Stackoverflow
Solution 5 - FirebaseRoenissView Answer on Stackoverflow
Solution 6 - FirebaseMarioView Answer on Stackoverflow
Solution 7 - Firebasebulgarian-beastView Answer on Stackoverflow
Solution 8 - FirebaseSAJJAN KView Answer on Stackoverflow
Solution 9 - FirebaseEnes KaraosmanView Answer on Stackoverflow
Solution 10 - FirebaseMiles Barette DuckworthView Answer on Stackoverflow
Solution 11 - FirebaseAbrahamView Answer on Stackoverflow
Solution 12 - FirebaseCelo ReisView Answer on Stackoverflow
Solution 13 - Firebasewilliam wolfeView Answer on Stackoverflow
Solution 14 - FirebaseJonathanView Answer on Stackoverflow
Solution 15 - FirebaseSuper NoobView Answer on Stackoverflow
Solution 16 - FirebaseGustave DupreView Answer on Stackoverflow
Solution 17 - FirebaseGavin CheborView Answer on Stackoverflow
Solution 18 - FirebaseRazvan FuleaView Answer on Stackoverflow
Solution 19 - FirebaseElijah BarazaView Answer on Stackoverflow
Solution 20 - FirebasephngView Answer on Stackoverflow
Solution 21 - Firebaseakshay_sushirView Answer on Stackoverflow
Solution 22 - FirebaseGijs van BeusekomView Answer on Stackoverflow
Solution 23 - FirebaseWiseTapView Answer on Stackoverflow
Solution 24 - FirebaseLorenzo SaniView Answer on Stackoverflow
Solution 25 - FirebasejbryanhView Answer on Stackoverflow
Solution 26 - FirebasemastodiluView Answer on Stackoverflow
Solution 27 - FirebaseHejtmusView Answer on Stackoverflow
Solution 28 - FirebaseAlex BalasView Answer on Stackoverflow
Solution 29 - FirebaseMikeView Answer on Stackoverflow
Solution 30 - FirebasebouraineView Answer on Stackoverflow
Solution 31 - FirebasePascal NitcheuView Answer on Stackoverflow
Solution 32 - FirebaseFabrizio BilleciView Answer on Stackoverflow