1

I am trying to deploy my Firebase Cloud Function with:

firebase deploy --only functions:helloWorld

My problem is that the command is sometimes successful, but most times it is failing with the error above. What might be the cause, and how to fix it?

I came across a similar question and tried many of the recommended solutions (clearing the npm cache and reinstalling the dependencies). Both solutions do not work reliably for me.

Here is the full console output:

=== Deploying to '<my-firebase-project>'...

i  deploying functions
✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (84.76 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: current functions in project: myFunction1(us-central1), myFunction2(us-central1), myFunction3(us-central1)...
i  functions: uploading functions in project: helloWorld(us-central1)
i  functions: updating Node.js 10 function helloWorld(us-central1)...
⚠  functions[helloWorld(us-central1)]: Deployment error.
Build failed: npm ERR! Maximum call stack size exceeded

npm ERR! A complete log of this run can be found in:
npm ERR!     /builder/home/.npm/_logs/2020-10-15T17_38_33_530Z-debug.log; Error ID: 49341d49


Functions deploy had errors with the following functions:
    helloWorld


To try redeploying those functions, run:
    firebase deploy --only "functions:helloWorld"


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

Error: Functions did not deploy properly.

Part of the problem is that I don't know where to find the full logs that the firebase deploy command output says are in /builder/home/.npm/_logs/2020-10-15T17_38_33_530Z-debug.log

And here are my firebase/functions config files:

./functions/index.js:

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

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
    response.send("Hello from Firebase!");
});

./firebase.json:

{
  "functions": {
    "predeploy": [
    ],
    "source": "functions",
    "runtime": "nodejs10"
  },
  "emulators": {
    "functions": {
      "port": 5001
    },...
  }
...
}

./functions/package.json:

{
  "name": "functions",
  "description": "Backend - Firebase Cloud Functions",
  "version": "1.0.0",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14.3.0"
  },
  "dependencies": {
    "config": "^3.3.1",
    "core-util-is": "^1.0.2",
    "crypto-js": "^4.0.0",
    "firebase-admin": "^9.1.1",
    "firebase-functions": "^3.11.0",
    "myapp_config": "file:./config"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

Dev stack:

  • macOS 10.15+
  • node version = v14.3.0
kip2
  • 6,473
  • 4
  • 55
  • 72
  • Are you saying that the log file it gives you is empty or missing or something? Just `cat` the file to see what's in it. The problem might be with your code, so you should edit the question to show the [complete minimal code](https://stackoverflow.com/help/minimal-reproducible-example) that reproduces the issue, so that anyone can reproduce this using the instructions you provide. – Doug Stevenson Oct 15 '20 at 15:53
  • @DougStevenson I don't know where the log file lives in. When I do `ls /builder/home` I get: `ls: /builder/home: No such file or directory`. Where is it supposed to be on a macOS machine? – kip2 Oct 15 '20 at 17:24
  • @DougStevenson I edited the question to provide a minimal example - is the `index.js` file above sufficient or need anything else? – kip2 Oct 15 '20 at 21:36
  • I don't see a problem here, but the contents of that log file is supposed to have what you need. If the CLI isn't giving you complete or actionable errors on what's going wrong during deployment, you should reach out to Firebase support directly. https://support.google.com/firebase/contact/support – Doug Stevenson Oct 15 '20 at 22:27

1 Answers1

0

Turns out the issue was how I was building the local dependency myapp_config in the line "myapp_config": "file:./config". I re-architected my app to remove [the need for] this line altogether and so far have not seen the deployment error again.

The ./config indicated on that line was actually a symlink to the config folder on my project root that I created with: ln -s ./config ./functions/config originally intended to deliver project-wide configuration-related modules into my functions scripts without having to manually copy over those files into functions. I suppose that much as Firebase Functions supports local Node.js dependencies, the CLI/npm somehow gets confused by or doesn't work well with symlinks (my guess is that it sees ./config and its symlink ./functions/config and goes into some infinite loop between them)

This other question sheds more light on the code structure I had and the problem I was trying to solve in the first place.

kip2
  • 6,473
  • 4
  • 55
  • 72