firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 930 forks source link

Firebase function deployment fails with 'missing' dependencies error #5673

Open ziziele opened 1 year ago

ziziele commented 1 year ago

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: ...regex-range@5.0.1 from lock file
npm ERR! Missing: brace-expansion@1.1.11 from lock file
npm ERR! Missing: balanced-match@1.0.2 from lock file
npm ERR! Missing: concat-map@0.0.1 from lock file
npm ERR! Missing: mimic-fn@2.1.0 from lock file
npm ERR! Missing: p-limit@2.3.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: 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: shebang-regex@3.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: has-flag@4.0.0 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: isexe@2.0.0 from lock file
npm ERR! Missing: ms@2.1.2 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: ms@2.1.2 from lock file
npm ERR! Missing: ms@2.1.2 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: p-try@2.2.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-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": "^11.5.0",
    "firebase-functions": "^4.2.0",
    "stripe": "^12.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"
      ]
    }
  ]
}

.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:

npm install -g firebase-tools

firebase login

firebase init functions - Use an existing project ...

cd functions

npm i stripe

edit index.js

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.

christhompsongoogle commented 1 year ago

Hi ziziele, does a regular npm install add the modules when run from the functions directory? I only see an npm i stripe in the bug report which may not install all required modules.

ziziele commented 1 year ago

Hi Chris,

I initially used npm i stripe only once before deploying my code. However, when I deployed it, I encountered an error, which prompted me to delete the node_modules folder and package_lock.json file. Afterward, I ran npm install, all inside the functions directory.

Despite repeating these steps several times, the error persisted. To troubleshoot the error, I manually installed the request packages indicated in the error message using npm install. However, as I installed more packages, it required more whenever I ran firebase deploy --only functions. My package-lock.json file now contains hundreds of packages.

christhompsongoogle commented 1 year ago

Is this a problem with Firebase or is the project corrupted? Is it possible to reproduce the error in a fresh project?

ziziele commented 1 year ago

Hi Chris, I've just tested with a fresh project and it has the same error.

These were the steps I took:

  1. npm install firebase-functions@latest firebase-admin@latest --save
  2. npm install -g firebase-tools
  3. firebase login
  4. firebase init functions
  5. JavaScript
  6. npm install
  7. cd functions and modified the existing index.js to:
    
    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!"); });



8. ` firebase deploy --only functions`

I have attached all the necessary files, including the `firebase.json` and the `functions/package.json` files, and the output log of the `firebase-debug.log` after running the deploy command with the debug flag.
[error.zip](https://github.com/firebase/firebase-tools/files/11206075/error.zip)
ziziele commented 1 year ago

Hi Chris,

I posted it on StackOverFlow and this is the right answer: https://stackoverflow.com/a/76044520/12640100

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 firebase-tools@11.17.0

Or at least it works for me.

christhompsongoogle commented 1 year ago

Following the steps above but I'm not able to repro

Node: v18.13.0 firebase-tools version: 11.25.3 OS: Ubuntu variant

Based on the S.O. Answer it's a problem finding functions.yaml - I'll continue investigating

Question: Do you have anything non-default in npmrc?

npm config list

taeold commented 1 year ago

Also @ziziele - do you mind sharing the version of node you are using locally and the version you are specifying when deploying to GCF?

e.g.

node -v
desk-pro commented 1 year ago

Hi @taeold. I face the same issue with Firebase 11.27.0. I've recently upgraded my version of node from 16.16 to 18.16. The problem occurs in both cases.

christhompsongoogle commented 1 year ago

Possibly related S.O. question https://stackoverflow.com/questions/76121723/what-is-functions-yaml

choleaoum commented 1 year ago

I've been chasing this problem all evening, I changed the engine field in the package.json file from 18 to 16 and it works after removing the node_module and running npm install. I was able to get the cloud function to also update by changing the engine to 18 BUT not running npm install. The error reappears soon as I change the engine back to 18, remove the node_modules and run npm install again.

I am running the latest firebase-tools, firebase-admin, and firebase-functions.

Update: Removing the package-lock.json file before deploying seems to fix it everytime.

google-oss-bot commented 1 year ago

Hey @ziziele. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

vbackeberg commented 1 year ago

Same issue and this resolves it:

Update: Removing the package-lock.json file before deploying seems to fix it everytime.

Node.js v18.16.0. Firebase 12.1.0 npm 9.6.7 Windows 11

michaelangeloio commented 1 year ago

I've been chasing this problem all evening, I changed the engine field in the package.json file from 18 to 16 and it works after removing the node_module and running npm install. I was able to get the cloud function to also update by changing the engine to 18 BUT not running npm install. The error reappears soon as I change the engine back to 18, remove the node_modules and run npm install again.

I am running the latest firebase-tools, firebase-admin, and firebase-functions.

Update: Removing the package-lock.json file before deploying seems to fix it everytime.

You should not remove the package-lock before deployment. That is a security and potential breaking change nightmare waiting to happen.

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@ziziele if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Rajdeep-Das commented 1 year ago

This issue is not solved. While deploying the latest functions build success. But in logs the same error.

Screenshot 2023-06-21 at 12 36 00 PM

{ "protoPayload": { "@type": "type.googleapis.com/google.cloud.audit.AuditLog", "status": { "code": 3, "message": "Build failed: ...: lines-and-columns@1.2.4 from lock file\nnpm ERR! Missing: is-arrayish@0.2.1 from lock file\nnpm ERR! Missing: ansi-styles@5.2.0 from lock file\nnpm ERR! Missing: react-is@18.2.0 from lock file\nnpm ERR! Missing: kleur@3.0.3 from lock file\nnpm ERR! Missing: sisteransi@1.0.5 from lock file\nnpm ERR! Missing: is-core-module@2.12.1 from lock file\nnpm ERR! Missing: path-parse@1.0.7 from lock file\nnpm ERR! Missing: supports-preserve-symlinks-flag@1.0.0 from lock file\nnpm ERR! Missing: shebang-regex@3.0.0 from lock file\nnpm ERR! Missing: buffer-from@1.1.2 from lock file\nnpm ERR! Missing: char-regex@1.0.2 from lock file\nnpm ERR! Missing: glob@7.2.3 from lock file\nnpm ERR! Missing: minimatch@3.1.2 from lock file\nnpm ERR! Missing: is-number@7.0.0 from lock file\nnpm ERR! Missing: picocolors@1.0.0 from lock file\nnpm ERR! Missing: convert-source-map@1.9.0 from lock file\nnpm ERR! Missing: makeerror@1.0.12 from lock file\nnpm ERR! Missing: tmpl@1.0.5 from lock file\nnpm ERR! Missing: isexe@2.0.0 from lock file\nnpm ERR! Missing: imurmurhash@0.1.4 from lock file\nnpm ERR! Missing: ms@2.1.2 from lock file\nnpm ERR! Missing: yallist@3.1.1 from lock file\nnpm ERR! Missing: ansi-styles@3.2.1 from lock file\nnpm ERR! Missing: escape-string-regexp@1.0.5 from lock file\nnpm ERR! Missing: supports-color@5.5.0 from lock file\nnpm ERR! Missing: color-convert@1.9.3 from lock file\nnpm ERR! Missing: color-name@1.1.3 from lock file\nnpm ERR! Missing: has-flag@3.0.0 from lock file\nnpm ERR! Missing: ms@2.1.2 from lock file\nnpm ERR! Missing: minimatch@3.1.2 from lock file\nnpm ERR! Missing: brace-expansion@1.1.11 from lock file\nnpm ERR! Missing: ms@2.1.2 from lock file\nnpm ERR! Missing: minimatch@3.1.2 from lock file\nnpm ERR! Missing: brace-expansion@1.1.11 from lock file\nnpm ERR! Missing: minimatch@3.1.2 from lock file\nnpm ERR! Missing: brace-expansion@1.1.11 from lock file\nnpm ERR! Missing: sprintf-js@1.0.3 from lock file\nnpm ERR! Missing: p-try@2.2.0 from lock file\nnpm ERR! Missing: brace-expansion@1.1.11 from lock file\nnpm ERR! \nnpm ERR! Clean install a project\nnpm ERR! \nnpm ERR! Usage:\nnpm ERR! npm ci\nnpm ERR! \nnpm ERR! Options:\nnpm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]\nnpm ERR! [-E|--save-exact] [-g|--global]\nnpm ERR! [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling]\nnpm ERR! [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]\nnpm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]\nnpm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]\nnpm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]\nnpm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]\nnpm ERR! \nnpm ERR! aliases: clean-install, ic, install-clean, isntall-clean\nnpm ERR! \nnpm ERR! Run \"npm help ci\" for more info\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /www-data-home/.npm/_logs/2023-06-21T06_17_19_692Z-debug-0.log; Error ID: beaf8772" }, "authenticationInfo": {}, "serviceName": "cloudfunctions.googleapis.com", "methodName": "google.cloud.functions.v1.CloudFunctionsService.CreateFunction", "resourceName": "projects/content-magic-tool/locations/us-central1/functions/authOnCreate" }, "insertId": "-oekmvud1nti", "resource": { "type": "cloud_function", "labels": { "region": "us-central1", "project_id": "content-magic-tool", "function_name": "authOnCreate" } }, "timestamp": "2023-06-21T06:17:31.521862Z", "severity": "ERROR", "logName": "projects/content-magic-tool/logs/cloudaudit.googleapis.com%2Factivity", "operation": { "id": "operations/Y29udGVudC1tYWdpYy10b29sL3VzLWNlbnRyYWwxL2F1dGhPbkNyZWF0ZS9XSjhET183UDZkSQ", "producer": "cloudfunctions.googleapis.com", "last": true }, "receiveTimestamp": "2023-06-21T06:17:32.401975695Z" }

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@ziziele if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

sebastien-f commented 1 year ago

I'm encountering the exact same issue. Builds fine, but when trying to deploy, getting multiple errors all looking the same :

Build failed: ...path-exists@3.0.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: ms@2.1.2 from lock file
npm ERR! Missing: cliui@8.0.1 from lock file

I recently upgraded to node 18.

All the versions would be :

I removed node_modules and package-lock.json before doing a clean npm install with the same errors at the end.

I investigated a few of the packages :

Not sure if that means anything as I never had to bother checking for that kind of stuff before, so I lack comparisons on that, but maybe that will give an idea to someone more knowledgeable than me on that topic.

Also FWIW, I'm trying to deploy functions v1 and v2.

By removing the package-lock.json, all the v1 functions managed to deploy, and the v2 failed, but that was my mistake as I had calls to functions.config(). I'll have to look into that, but that's unrelated.

As my project is 2 years old, I wondered if I'm not missing anything that was added afterwards. So I created a new project and its functions folder, uncommented the helloWorld function and tried to deploy it, with the same error (as @ziziele) did.

PratyakshGupta48 commented 1 year ago

How I solved the issue.

This issue started appearing while deploying my cloud functions a week ago. I could not find a solution and was getting mad. I read and tried every information on the internet to resolve the error, but no success.

Finally, I decided to reset my machine, and then tried to redeploy the cloud function with the exact same configuration and versions and this time it worked!

Also, thoroughly comparing I found that when we install NodeJS on our machine , with all the required packages python311 also gets installed which helps in downloading of the missing dependencies mentioned in the error and i had deleted python311 folder from C drive thinking it as junk which might is causing all the trouble.

I hope my comment helps in resolving the issue!🫡 Screenshot 2023-08-07 220438

paul019 commented 1 year ago

This is still not solved. I encounter exactly the same problem.

The only thing that works for me is deleting package-lock.json before deployment. However, as @michaelangeloio has already pointed out, this is not a good idea.

Edit: I also tried npm config set legacy-peer-deps false and npm ci as suggested here, but it did not work. Contrary to @sebastien-f, I am experiencing the issue on a Mac.

sewellstephens commented 1 year ago

Removing package-lock seems fine to me.

sebastien-f commented 1 year ago

Removing package-lock seems fine to me.

https://stackoverflow.com/a/54127283/111625. Short version :

Conclusion: don't ever delete package-lock.json.

That being said, in many scenarios that won't be an issue, but why makes the symptom disappear instead of curing the illness ?

sebastien-f commented 1 year ago

This is still not solved. I encounter exactly the same problem.

The only thing that works for me is deleting package-lock.json before deployment. However, as @michaelangeloio has already pointed out, this is not a good idea.

Edit: I also tried npm config set legacy-peer-deps false and npm ci as suggested here, but it did not work. Contrary to @sebastien-f, I am experiencing the issue on a Mac.

After running the config set command from npm, try running npm config list to make sure that it was taken into account. You should see a line with : legacy-peer-deps = false, not starting with a ;.

If that's not it, if you can share somewhere the full error log from google cloud console regarding the deployment, I can offer to have a look at it, to see if something strikes me. If I remember correctly, firebase should provide a link to it when it fails.

paul019 commented 1 year ago

When running npm config list I indeed get legacy-peer-deps = false.

I exported the error log from Google Cloud Console (see below). However, as it is very long and repetitive in the middle, I replaced one part with ....

Thank you very much in advance!

Error log ``` 2023-10-03 15:07:12.794 CEST Step #2 - "build": Already have image (with digest): europe-west3-docker.pkg.dev/gae-runtimes/gcp/buildpacks/google-gae-18/nodejs/builder:nodejs_20231002_RC00 2023-10-03 15:07:13.590 CEST Step #2 - "build": ===> ANALYZING 2023-10-03 15:07:14.071 CEST Step #2 - "build": Timer: Analyzer started at 2023-10-03T13:07:14Z 2023-10-03 15:07:14.108 CEST Step #2 - "build": Image with name "europe-west3-docker.pkg.dev/flutter-test2-af2a7/gcf-artifacts/http__users__create_user:latest" not found 2023-10-03 15:07:14.226 CEST Step #2 - "build": Timer: Analyzer ran for 154.735085ms and ended at 2023-10-03T13:07:14Z 2023-10-03 15:07:14.226 CEST Step #2 - "build": ===> DETECTING 2023-10-03 15:07:14.236 CEST Step #2 - "build": Timer: Detector started at 2023-10-03T13:07:14Z 2023-10-03 15:07:14.378 CEST Step #2 - "build": google.nodejs.runtime 1.0.0 2023-10-03 15:07:14.378 CEST Step #2 - "build": google.utils.archive-source 0.0.1 2023-10-03 15:07:14.378 CEST Step #2 - "build": google.nodejs.npm 1.0.0 2023-10-03 15:07:14.378 CEST Step #2 - "build": google.nodejs.functions-framework 0.9.4 2023-10-03 15:07:14.378 CEST Step #2 - "build": google.config.entrypoint 0.9.0 2023-10-03 15:07:14.378 CEST Step #2 - "build": google.utils.label-image 0.0.2 2023-10-03 15:07:14.378 CEST Step #2 - "build": Timer: Detector ran for 142.091722ms and ended at 2023-10-03T13:07:14Z 2023-10-03 15:07:14.378 CEST Step #2 - "build": ===> RESTORING 2023-10-03 15:07:14.378 CEST Step #2 - "build": Timer: Restorer started at 2023-10-03T13:07:14Z 2023-10-03 15:07:14.602 CEST Step #2 - "build": Restoring metadata for "google.nodejs.runtime:node" from cache 2023-10-03 15:07:14.604 CEST Step #2 - "build": Restoring metadata for "google.nodejs.npm:npm_modules" from cache 2023-10-03 15:07:14.604 CEST Step #2 - "build": Restoring data for "google.nodejs.runtime:node" from cache 2023-10-03 15:07:14.604 CEST Step #2 - "build": Restoring data for "google.nodejs.npm:npm_modules" from cache 2023-10-03 15:07:17.231 CEST Step #2 - "build": Timer: Restorer ran for 2.85228193s and ended at 2023-10-03T13:07:17Z 2023-10-03 15:07:17.231 CEST Step #2 - "build": ===> BUILDING 2023-10-03 15:07:17.231 CEST Step #2 - "build": Timer: Builder started at 2023-10-03T13:07:17Z 2023-10-03 15:07:17.246 CEST Step #2 - "build": === Node.js - Runtime (google.nodejs.runtime@1.0.0) === 2023-10-03 15:07:17.246 CEST Step #2 - "build": Using runtime version from GOOGLE_RUNTIME_VERSION: 16.20.2 2023-10-03 15:07:17.247 CEST Step #2 - "build": ***** CACHE HIT: "nodejs" 2023-10-03 15:07:17.247 CEST Step #2 - "build": Node.js v16.20.2 cache hit, skipping installation. 2023-10-03 15:07:17.249 CEST Step #2 - "build": Warning: BOM table is deprecated in this buildpack api version, though it remains supported for backwards compatibility. Buildpack authors should write BOM information to .sbom., launch.sbom., or build.sbom.. 2023-10-03 15:07:17.249 CEST Step #2 - "build": Warning: BOM table is deprecated in this buildpack api version, though it remains supported for backwards compatibility. Buildpack authors should write BOM information to .sbom., launch.sbom., or build.sbom.. 2023-10-03 15:07:17.249 CEST Step #2 - "build": Warning: BOM table is deprecated in this buildpack api version, though it remains supported for backwards compatibility. Buildpack authors should write BOM information to .sbom., launch.sbom., or build.sbom.. 2023-10-03 15:07:17.264 CEST Step #2 - "build": === Utils - Archive Source (google.utils.archive-source@0.0.1) === 2023-10-03 15:07:17.363 CEST Step #2 - "build": Adding image label google.source-archive: /workspace/.googlebuild/source-code.tar.gz 2023-10-03 15:07:17.380 CEST Step #2 - "build": === Node.js - Npm (google.nodejs.npm@1.0.0) === 2023-10-03 15:07:17.414 CEST Step #2 - "build": ***** CACHE MISS: "npm_modules" 2023-10-03 15:07:17.582 CEST Step #2 - "build": Installing application dependencies. 2023-10-03 15:07:18.042 CEST Step #2 - "build": -------------------------------------------------------------------------------- 2023-10-03 15:07:18.042 CEST Step #2 - "build": Running "npm ci --quiet (NODE_ENV=production)" 2023-10-03 15:07:26.408 CEST Step #2 - "build": npm 2023-10-03 15:07:26.408 CEST Step #2 - "build": ERR! code EUSAGE 2023-10-03 15:07:26.457 CEST Step #2 - "build": npm 2023-10-03 15:07:26.457 CEST Step #2 - "build": 2023-10-03 15:07:26.457 CEST Step #2 - "build": ERR! 2023-10-03 15:07:26.458 CEST Step #2 - "build": 2023-10-03 15:07:26.458 CEST Step #2 - "build": npm 2023-10-03 15:07:26.458 CEST Step #2 - "build": ERR! `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. 2023-10-03 15:07:26.458 CEST Step #2 - "build": npm ERR! 2023-10-03 15:07:26.458 CEST Step #2 - "build": 2023-10-03 15:07:26.458 CEST Step #2 - "build": npm 2023-10-03 15:07:26.458 CEST Step #2 - "build": ERR! 2023-10-03 15:07:26.458 CEST Step #2 - "build": Missing: jest@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: @jest/core@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: @jest/types@29.6.3 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: import-local@3.1.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: jest-cli@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: @jest/console@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: @jest/reporters@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: @jest/test-result@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: @jest/transform@29.7.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: ansi-escapes@4.3.2 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: ci-info@3.8.0 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ERR! Missing: exit@0.1.2 from lock file 2023-10-03 15:07:26.459 CEST Step #2 - "build": npm ... 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! Clean install a project 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! Usage: 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! npm ci 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! Options: 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [--omit [--omit ...]] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [-w|--workspace [-w|--workspace ...]] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links] 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! aliases: clean-install, ic, install-clean, isntall-clean 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! Run "npm help ci" for more info 2023-10-03 15:07:26.490 CEST Step #2 - "build": 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! A complete log of this run can be found in: 2023-10-03 15:07:26.490 CEST Step #2 - "build": npm ERR! /www-data-home/.npm/_logs/2023-10-03T13_07_18_417Z-debug-0.log 2023-10-03 15:07:26.491 CEST Step #2 - "build": Timer: Builder ran for 9.259496916s and ended at 2023-10-03T13:07:26Z 2023-10-03 15:07:26.491 CEST Step #2 - "build": ERROR: failed to build: exit status 1 ```
sebastien-f commented 1 year ago

It's a bit different from what I had (not by a large account, but still). If you did not tried it yet, what you could also do would be moving your node_modules and package-lock.json outside of your project directory (you could delete them also, but you never know) and then run npm install again, then try to deploy it, just to make sure that it's really up to date with your project.

Also, not sure if you can, but I'd try copying the project to another computer (even a virtual machine), then npm install and then trying to deploy it from that other machine, just to see if that's not something specific on your mac.

paul019 commented 1 year ago

Thank you! I already tried to delete node_modules and package-lock.json and run npm install again. Unfortunately, that did not work.

I will try to run it on a Windows machine (or virtual machine) later.

ytetsuro commented 9 months ago

I am also experiencing this. It is very strange, but once the functions emulator fails to start up, the next time it succeeds in starting up the emulator.

# fail!!
$ cd functions && rm -rf build && npm ci && firebase emulators:start --only functions
# success!!
$ cd functions && rm -rf build && npm ci && firebase emulators:exec --only functions "echo hello" && firebase emulators:start --only functions
ekaram commented 7 months ago

I am still experiencing this issue.

npm ERR! npm ERR! 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. npm ERR! npm ERR! Missing: ms@2.0.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! [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling] npm ERR! [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] npm ERR! [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]] npm ERR! [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit] npm ERR! [--no-bin-links] [--no-fund] [--dry-run] npm ERR! [-w|--workspace [-w|--workspace ...]] 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

sewellstephens commented 7 months ago

remove package-lock.json. thats what ive been doing and its worked for months ever since

sewellstephens commented 7 months ago

@ekaram it may not be best idea or even good practice, but at the end of the day that's all that works and has ever. no other solutions above do sh*t

dzivoing commented 7 months ago

I am getting this error when i am trying to tsc --watch. If a code throws an exception inside a function i try to change the code and build the project the code is built but i get this error

ahmadtech199 commented 4 months ago

Add this line into terminal V Code sudo npm install -g firebase-tools

skwny commented 4 months ago

I'm having the same problem:

Build failed with status: FAILURE and message: npm ERR! code EUSAGE npm ERR! npm ERR! 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. npm ERR! npm ERR! Missing: string-width-cjs@4.2.3 from lock file npm ERR! Missing: strip-ansi-cjs@6.0.1 from lock file npm ERR! Missing: wrap-ansi-cjs@7.0.0 from lock file npm ERR! Missing: safe-buffer@5.1.2 from lock file npm ERR! Missing: safe-buffer@5.1.2 from lock file npm ERR! Missing: safe-buffer@5.1.2 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! [--install-strategy <hoisted|nested|shallow|linked>] [--legacy-bundling] npm ERR! [--global-style] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] npm ERR! [--include <prod|dev|optional|peer> [--include <prod|dev|optional|peer> ...]] npm ERR! [--strict-peer-deps] [--foreground-scripts] [--ignore-scripts] [--no-audit] npm ERR! [--no-bin-links] [--no-fund] [--dry-run] npm ERR! [-w|--workspace [-w|--workspace ...]] 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

Skippou commented 3 months ago

@ytetsuro I have the exact same problem. Running it twice consistently works.

I like your solution. It seems like you've also spent a lot of time to fix this. You definitely read the docs.

I'd like to know if there is a more elegant fix in the future.

iKrishnaSahu commented 2 months ago

Facing similar issue while deploying cloud function

removing package-lock.json before deploying fixed this issue for me. But this is not a proper solution.

darthwalsh commented 2 months ago

(Some more details that might help others coming from Google search find this.)

When I deploy the functions with package-lock.json existing, I get the error:

=== Node.js - Npm (google.nodejs.npm@1.1.0) ===
***** CACHE MISS: "npm_modules"
Installing application dependencies.
--------------------------------------------------------------------------------
Running "npm ci --quiet (NODE_ENV=production)"
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error     <https://github.com/npm/cli/issues>
npm error A complete log of this run can be found in: /www-data-home/.npm/_logs/2024-07-15T19_50_02_938Z-debug-0.log
Done "npm ci --quiet (NODE_ENV=production)" (7m41.268669372s)
--------------------------------------------------------------------------------
failed to build: (error ID: beaf8772):
Timer: Builder ran for 7m44.29164638s and ended at 2024-07-15T19:57:44Z
ERROR: failed to build: exit status 1

@christhompsongoogle does this look like another symptom of the same issue? Now npm ci is hitting some internal crash. I don't know how I can get access to /www-data-home/.npm/_logs of my firebase function Cloud Build but that might have some more enlightening facts. If this is a new problem I can instead make a new github issue?

When I delete the lock file or add "package-lock.json" to firebase.json's functions.ignore[] then I get a successful build, although it adds some extra build time to recreate the lock file...

=== Node.js - Npm (google.nodejs.npm@1.1.0) ===
Generating package-lock.json.
WARNING: *** Improve build performance by generating and committing package-lock.json.
--------------------------------------------------------------------------------
Running "npm install --package-lock-only --quiet"
up to date, audited 868 packages in 15s
Done "npm install --package-lock-only --quiet" (15.222930181s)
***** CACHE MISS: "npm_modules"
Installing application dependencies.
--------------------------------------------------------------------------------
Running "npm ci --quiet (NODE_ENV=production)"
added 275 packages, and audited 276 packages in 8s
Done "npm ci --quiet (NODE_ENV=production)" (8.33702695s)
=== Node.js - Functions Framework (google.nodejs.functions-framework@0.9.4) ===
--------------------------------------------------------------------------------
Running "node --check index.js"
....
DebuggingBee commented 1 month ago

I updated multiple things before I could successfully deploy firebase functions. It took some while, but I did solve it:

In the end it all worked out.

saldous commented 3 weeks ago

I'm experiencing this same issue. Frustrating that so many people are reporting it, yet this is closed with no solution. :(

sewellstephens commented 3 weeks ago

@saldous did you try deleting package-lock.json?

saldous commented 3 weeks ago

@saldous did you try deleting package-lock.json?

yes, while that works I'm sure that's not the official solution/fix? It's a temporary workaround.