7

I initialized a new firebase project in my project. I added functions to my project and I am trying to deploy the default helloWorld function.

const functions = require("firebase-functions");

// // Create and deploy your first functions
// // https://firebase.google.com/docs/functions/get-started
//
exports.helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

When I do this I get the following error saying it is missing a lot of packages I have never heard of.

i  functions: updating Node.js 16 function helloWorld(us-central1)...
Build failed: ...c-fn@2.1.0 from lock file
npm ERR! Missing: error-ex@1.3.2 from lock file
npm ERR! Missing: json-parse-even-better-errors@2.3.1 from lock file
npm ERR! Missing: lines-and-columns@1.2.4 from lock file
npm ERR! Missing: is-arrayish@0.2.1 from lock file
npm ERR! Missing: find-up@4.1.0 from lock file
npm ERR! Missing: ansi-styles@5.2.0 from lock file
npm ERR! Missing: react-is@18.2.0 from lock file
npm ERR! Missing: kleur@3.0.3 from lock file
npm ERR! Missing: sisteransi@1.0.5 from lock file
npm ERR! Missing: is-core-module@2.11.0 from lock file
npm ERR! Missing: path-parse@1.0.7 from lock file
npm ERR! Missing: supports-preserve-symlinks-flag@1.0.0 from lock file
npm ERR! Missing: resolve-from@5.0.0 from lock file
npm ERR! Missing: buffer-from@1.1.2 from lock file
npm ERR! Missing: escape-string-regexp@2.0.0 from lock file
npm ERR! Missing: char-regex@1.0.2 from lock file
npm ERR! Missing: glob@7.2.3 from lock file
npm ERR! Missing: is-number@7.0.0 from lock file
npm ERR! Missing: picocolors@1.0.0 from lock file
npm ERR! Missing: convert-source-map@1.9.0 from lock file
npm ERR! Missing: makeerror@1.0.12 from lock file
npm ERR! Missing: tmpl@1.0.5 from lock file
npm ERR! Missing: yallist@3.1.1 from lock file
npm ERR! Missing: ansi-styles@3.2.1 from lock file
npm ERR! Missing: escape-string-regexp@1.0.5 from lock file
npm ERR! Missing: supports-color@5.5.0 from lock file
npm ERR! Missing: color-convert@1.9.3 from lock file
npm ERR! Missing: color-name@1.1.3 from lock file
npm ERR! Missing: has-flag@3.0.0 from lock file
npm ERR! Missing: locate-path@5.0.0 from lock file
npm ERR! Missing: argparse@1.0.10 from lock file
npm ERR! Missing: sprintf-js@1.0.3 from lock file
npm ERR! Missing: p-locate@4.1.0 from lock file
npm ERR! Missing: p-limit@2.3.0 from lock file
npm ERR! Missing: p-try@2.2.0 from lock file
npm ERR! Missing: cliui@8.0.1 from lock file
npm ERR! Missing: yargs-parser@21.1.1 from lock file
npm ERR! Missing: locate-path@5.0.0 from lock file
npm ERR! Missing: p-locate@4.1.0 from lock file
npm ERR! Missing: p-limit@2.3.0 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-02-28T21_49_46_615Z-debug-0.log; Error ID: beaf8772

Functions deploy had errors with the following functions:
    helloWorld(us-central1)

I installed the firebase-functions package, also let firebase install it's packages in the setup when initializing. I tried removing node_modules, remove cache, remove lock, reinstalling. I tried removing firebase from my project and reinitializing it. I tried changing my Node version.

I am really clueless.

Hope someone can help me!

Thanks!

Laurens Smid
  • 511
  • 3
  • 15

3 Answers3

17

FIXED! I fixed this by removing the lockfile after installing the packages and then deploy to firebase without lockfile.

Laurens Smid
  • 511
  • 3
  • 15
  • 5
    I have no idea, why this works... but kudos man – Lewis Mar 03 '23 at 06:35
  • 1
    Looks like Google/Firebase keeps using the lockfile that it already has or generates its own. Until we push no lockfile, then it wil overwrite it with the new packages. You’ll be fine if you just exclude the lock from your deployment! – Laurens Smid Mar 04 '23 at 07:09
  • Oh, I can't upvote this answer that's strange... Oh yea right, I forgot about this. – Ruan May 22 '23 at 10:59
  • In theory, the lockfile is serving a worthwhile purpose. It's probably healthier to regenerate it- rename the old one to .old or something and then run `npm install` from within your functions directory- than to delete it outright. The underlying issue might be some corruption of the lockfile; my regenerated file was twice as large as the one I had when I got this error. – NNSkelly Jun 14 '23 at 19:26
  • 1
    @LaurensSmid could you please elaborate a little bit, what is lockfile in here? I am sorry, I am a beginner in Node JS. do you mean package-lock.json file? – Alexa289 Jul 02 '23 at 09:59
  • 1
    ahh you are correct, I can deploy to firebase after deleting package-lock.json file. thank you very much! – Alexa289 Jul 02 '23 at 10:03
  • Wow, I wasted a day solving it, regenerating lock file, asking firebase support (btw. they didn't have the solution), and this simple hack worked! Thanks! – Marcin Żmigrodzki Jul 02 '23 at 12:16
0

Another fix! You can also use this command while in your functions directory:

npm i --package-lock-only

This updates the package-lock.json according to the docs of npm v6, npm v7, or the latest version.

Read more here - Is there a way to force npm to generate package-lock.json?

Emmanuel .C
  • 298
  • 2
  • 6
-1

I know you have already found a solution, I have came across a similar issue, my problem was that I was in the wrong directory, to deploy function I believe you need to be within the functions directory of the firebase project.

Jacob
  • 11
  • 3