Firebase function deployment fails with 'missing' dependencies error
Asked Answered
P

6

6

I am encountering an error when attempting to deploy a Firebase function. Despite deleting node_modules and package-lock.json, running npm install, and executing firebase deploy --only functions many times, the build process still fails with the following error:

Build failed: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR! Missing: [email protected] from lock file
npm ERR!
npm ERR! Clean install a project
npm ERR!
npm ERR! Usage:
npm ERR! npm ci
npm ERR!
npm ERR! Options:
npm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]      
npm ERR! [-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
npm ERR! [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
npm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
npm ERR!
npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
npm ERR!
npm ERR! Run "npm help ci" for more info

npm ERR! A complete log of this run can be found in:
npm ERR!     /www-data-home/.npm/_logs/2023-04-09T09_55_08_623Z-debug-0.log; Error ID: beaf8772      

Functions deploy had errors with the following functions:
        update(asia-east2)
i  functions: cleaning up build files...

Error: There was an error deploying functions

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^10.0.0",
    "firebase-functions": "^4.0.0",
    "stripe": "^8.0.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^3.0.0"
  },
  "private": true,
  "engines": {
    "node": "16"
  }
}

firebase.json

{
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ]
    }
  ]
}

I don't have .gcloudignore but .gitignore:

node_modules/

I have manually npm installed each of them but anytime I execute firebase deploy --only functions, it keeps asking for more. Now my package-lock.json has hundreds of packages.

The code I'm testing:

exports.helloWorld = functions
  .region("asia-east2")
  .https.onRequest((request, response) => {
    functions.logger.info("Hello logs!", { structuredData: true });
    response.send("Hello from Firebase!");
  });

The steps I took:

  1. npm install -g firebase-tools

  2. firebase login

  3. firebase init functions - Use an existing project ...

  4. cd functions

  5. npm i stripe

  6. edit index.js

  7. firebase deploy --only functions

On the Firebase Dashboard, this function is indicated by a red triangle with the message 'Function deployment failed. Please try again.'

I have also tried updating the affected packages in my package.json file, but the error persists.

I am unsure what could be causing this issue, and I would greatly appreciate any guidance or suggestions on how to fix it. Thank you for your help.

Pediatrics answered 9/4, 2023 at 10:10 Comment(3)
Please share your package.json and firebase.json without those we cannot tell what configuration you are running.Oliva
Also what is in .gcloudignore? Has this function ever deployed successfully? Do other functions deploy successfully? What are the contents of /www-data-home/.npm/_logs/2023-04-09T09_55_08_623Z-debug-0.log? Does it deploy from a local device but not from this device?Wershba
@RohitKharche I've added both. @Wershba I don't see the gcloudignore, only the .gitignore and it has only node_modules/ in it. This is my first-ever deployment. How to find the contents of /www-data-home/.npm/_logs/2023-04-09T09_55_08_623Z-debug-0.log? I tried firebase functions:log but I don't think I got the right log. I'm deploying it from a local device.Pediatrics
M
6

I have checked firebase-debug.log in this issue and it contains Could not find functions.yaml. Must use http discovery :

...
[debug] [2023-04-12T00:48:22.311Z] Building nodejs source
[debug] [2023-04-12T00:48:22.312Z] Could not find functions.yaml. Must use http discovery
[debug] [2023-04-12T00:48:22.319Z] Found firebase-functions binary at 'C:\Users\munic\Desktop\programming\penvie\testfunc\functions\node_modules\.bin\firebase-functions'
[debug] [2023-04-12T00:48:22.460Z] Serving at port 8008

[debug] [2023-04-12T00:48:22.666Z] Got response from /__/functions.yaml {"endpoints":{"helloWorld":{"platform":"gcfv1","availableMemoryMb":null,"timeoutSeconds":null,"minInstances":null,"maxInstances":null,"ingressSettings":null,"serviceAccountEmail":null,"vpc":null,"httpsTrigger":{},"entryPoint":"helloWorld"}},"specVersion":"v1alpha1","requiredAPIs":[]}
[debug] [2023-04-12T00:48:22.672Z] shutdown requested via /__/quitquitquit

[info] i  functions: preparing functions directory for uploading... 
[info] i  functions: packaged C:\Users\munic\Desktop\programming\penvie\testfunc\functions (63.59 KB) for uploading 
...

After reading a similar issue, I see that they recommend downgrading firebase-tools to 10.0.0, 10.8.0, 11.17.0, 11.18.0, 11.20.0, or 11.22.0. Mostly they prefer to downgrade it to 11.17.0.

npm i -g [email protected]
Maffei answered 18/4, 2023 at 12:18 Comment(8)
Not working even after downgrading to 11.17.0Mazy
@Mazy what is your node version?Maffei
@Maffei my node version - v16.17.1Mazy
@Mazy downgrade to v16.16.0 may help.Maffei
@Maffei But, my other Firebase functions projects are working fine. Only this particular project has this issue, do you need any other info regarding this specific project?Mazy
@Mazy Let us see the firebase-debug.log firstMaffei
@Maffei for some reason It worked again. (I did not do anything) Thanks for your replies.Mazy
@jordy ily, firebase ihyCourtenay
C
3

Thanks to Jordy's answer, I could deploy after downgrading firebase-tools:

npm i -g [email protected]

However, I'd like to complete the answer by saying that you must have node 16 for this to work.

The firebase-tools downgrade by itself didn't work on my node 18.

Cashbook answered 14/8, 2023 at 14:43 Comment(2)
I am having the same issue here. while updating my repo to use Node 18.19.0, everything works well locally (i.e tsc/ serving functions) but when deploying it keeps popping an issue peer deps and every time one is solved it pops another one. Did you managed to solve this or the issue with node 18?Psychosis
No, I'm still using version 16.Cashbook
G
1

Had the same error, triggered on the build server by npm ci saying :

npm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing

It was due to having a global legacy-peer-deps enabled on npm. Once I removed it and ran npm install, the error was gone and functions deploied.

Galicia answered 11/8, 2023 at 10:41 Comment(0)
C
1

Another thing on top of the firebase-tools, that seemed to help was downgrading firebase-functions to 3.24.1

so my dependencies are now

  "dependencies": {
    "firebase-admin": "^11.8.0",
    "firebase-functions": "3.24.1",
    "firebase-tools": "^11.17.0",
    "vite": "^4.5.0"
  }

And it's actually building, ty Jordy!

Courtenay answered 18/10, 2023 at 11:53 Comment(0)
W
0

After reproducing your issue, I took the following steps to debug it.

There are a few things that you should check before starting the debugging process:

  1. Check your Firebase project is upgraded to the Blaze Plan first. After that, connect that upgraded project with your code.
  2. Make sure your node environment is version 16. I am using 16.13.1, which works. You must use version 16 because, in your package.json file, you have mentioned the node version as 16. You can use nvm [Node Version Manager] for this. I strongly recommend that you use the same version as mine.
  3. Run the npm install in your project again with your updated node version. It will successfully install all the dependencies.
  4. Delete the older Firebase cloud function and try re-deploying.
Wheelchair answered 17/4, 2023 at 2:9 Comment(3)
Thank you for your input. I did all the steps you said. I even created a fresh project with Blaze Plan and Node 18. I posted the problem on Firebase's GitHub and I think they are working on it: https://github.com/firebase/firebase-tools/issues/5673Pediatrics
Did you try using node version 16.13.1? Just curious if that worked or not.Wheelchair
I'm using 16.17.0 actually.Pediatrics
K
0

I managed to get this working with the latest firebase-tools and Node versions by un-setting the global legacy-peer-deps option.

npm config set legacy-peer-deps false

I then did an npm i in my project folder (not sure if that was strictly necessary) and then the next firebase deploy worked.

I wrote a bit more about this on the issues thread here: https://github.com/firebase/firebase-tools/issues/5673#issuecomment-2425199290

Kktp answered 20/10 at 20:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.